当前位置:网站首页>Luogup2756 pilot pairing scheme problem (maximum flow)
Luogup2756 pilot pairing scheme problem (maximum flow)
2022-06-30 05:45:00 【Coco_ T_】
A typical bipartite graph matching problem
Foreign pilots as X Ministry , British pilots as Y Ministry
The source points to X Partial edge , Capacity of 1
Y The local convergence point is connected to the edge , Capacity of 1
X Department and Y Between the two sides , Capacity of 1
crazy WA It's not just because of the scheme output
I use an array record here ( Foreign pilot , British pilots ) The number of the side
The default value of array is 0
dinic Then judge whether the capacity of the edge is 0
Note that you need to determine whether the number of records in the array is valid ( Is it the default value )
Tip
Be careful bfs and dfs When , You need to determine whether the current edge has capacity
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
using namespace std;
const int INF=0x33333333;
const int N=105;
int mp[N][N];
int st[N],tot=-1;
struct node{
int x,y,v,nxt;
};
node way[N*N];
int n,m,s,t;
void addway(int u,int w,int z) {
tot++;
way[tot].x=u;
way[tot].y=w;
way[tot].v=z;
way[tot].nxt=st[u];
st[u]=tot;
}
queue<int> q;
int cur[N];
int deep[N];
int bfs() {
memset(deep,-1,sizeof(deep));
for (int i=0;i<=n+1;++i) cur[i]=st[i];
q.push(s);
deep[s]=1;
while (!q.empty()) {
int r=q.front();
q.pop();
for (int i=st[r];i!=-1;i=way[i].nxt) {
int y=way[i].y;
if (way[i].v && deep[y]==-1) {
//way[i].v!=0
q.push(y);
deep[y]=deep[r]+1;
}
}
}
return deep[t]!=-1;
}
int dfs(int now,int t,int limit) {
if (now==t || !limit) return limit;
int f,flow=0;
for (int i=cur[now];i!=-1;i=way[i].nxt) {
cur[now]=i;
if (way[i].v && deep[way[i].y]==deep[now]+1 && (f=dfs(way[i].y,t,min(limit,way[i].v)))) {
way[i].v-=f;
way[i^1].v+=f;
limit-=f;
flow+=f;
if (!limit) break;
}
}
return flow;
}
int dinic() {
int ans=0;
while (bfs()) {
ans+=dfs(s,t,INF);
}
return ans;
}
int main()
{
memset(st,-1,sizeof(st));
scanf("%d%d",&m,&n);
s=0;
t=n+1;
for (int i=1;i<=n;i++) {
if (i<=m) {
addway(s,i,1);
addway(i,s,0);
}
else {
addway(i,t,1);
addway(t,i,0);
}
}
int x,y;
scanf("%d%d",&x,&y);
while (x!=-1 && y!=-1) {
addway(x,y,1);
mp[x][y]=tot;
addway(y,x,0);
scanf("%d%d",&x,&y);
}
printf("%d\n",dinic());
for (int i=1;i<=m;++i) {
for (int j=m+1;j<=n;++j) {
if (mp[i][j] && way[mp[i][j]].v == 0) {
printf("%d %d\n",i,j);
}
}
}
return 0;
}
边栏推荐
- El table lazy load refresh
- Remote sensing image /uda:curriculum style local to global adaptation for cross domain remote sensing image segmentation
- Did you know that WPS can turn on eye protection mode?
- After getting these performance test decomposition operations, your test path will be more smooth
- Qt之QListView的简单使用(含源码+注释)
- Unity gets the resolution of the game view
- Bev instance prediction based on monocular camera (iccv 2021)
- C语言基础小操作
- Rotating box target detection mmrotate v0.3.1 getting started
- Word frequency statistics (string, list)
猜你喜欢
Here comes the nearest chance to Ali
C语言基础小操作
Rotating frame target detection mmrotate v0.3.1 training dota data set (II)
[secretly kill little partner pytorch20 days] - [day4] - [example of time series data modeling process]
Solidity - 安全 - 重入攻击(Reentrancy)
UE4_ Editor UMG close window cannot destroy UMG immediately
Switch to software testing and report to the training class for 3 months. It's a high paying job. Is it reliable?
云服务器部署 Web 项目
The fourth day of learning C language for Asian people
86. separate linked list
随机推荐
图扑软件基于钻孔数据的三维地质模型可视化
Acwing winter vacation daily question 2022 punch in day 11
UML tools
Database SQL language 06 single line function
Wechat applet training 2
Responsive layout
ECS deployment web project
Digital signature——
Unityshader learning notes - Basic Attributes
UE4_ Editor UMG close window cannot destroy UMG immediately
Introduction to Redux: initial experience of Redux
Xijiao 21 autumn "motor and drive" online homework answer sheet (I) [standard answer]
Idea of capturing mobile terminal variant combination
旋转框目标检测mmrotate v0.3.1 训练DOTA数据集(二)
Online assignment of C language program design in the 22nd spring of Western Polytechnic University
领导:谁再用 Redis 过期监听实现关闭订单,立马滚蛋!
Learning automation ppt
Finally someone can make the server so straightforward
OSPF - authentication and load balancing summary (including configuration commands)
Xi'an Jiaotong automation control theory test simulation question [standard answer]