当前位置:网站首页>Network flow 24 questions (round table questions)
Network flow 24 questions (round table questions)
2022-06-24 21:10:00 【GS_ Qiang】
1. Round table questions
The main idea of the topic :
m Representatives of different units attended an international conference . The first i Units sent r_i A representative .
The conference restaurant has n A dining table , The first i Table can accommodate c_i A representative .
Representatives from the same unit do not eat at the same table .
Ideas :
First, I want to know how to build a map , Because representatives from the same unit do not eat at the same table , So you can connect each unit with each dining table , Capacity of 1.
Then create a source point by yourself , So connect the source point to each unit , The number of people in capacity .
Create another meeting point , Each table is connected to the meeting point , The capacity is the capacity of each table .
So it is similar to building such a picture :
Then run from the source point to the sink point with the maximum flow , Just set the maximum flow plate ..
Code :
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
const int INF=0x3f3f3f3f;
int n,m,flow,ss,tt;
struct node {
int to,next,cost;
}E[N << 1];
int head[N],tot;
void init() {
memset(head,-1,sizeof(head));
tot=0;
}
void add(int from,int to,int co) {
E[tot].to=to,E[tot].cost=co,E[tot].next=head[from],head[from]=tot++;
E[tot].to=from,E[tot].cost=0,E[tot].next=head[to],head[to]=tot++;
}
int deaph[N];// Depth of layering diagram
bool bfs(int s,int t) {
memset(deaph,-1,sizeof(deaph));
queue<int>q;
deaph[s]=0;
q.push(s);
while(!q.empty()) {
int x=q.front();
q.pop();
if(x==t) return true;
for(int i=head[x];~i;i=E[i].next) {
int now=E[i].to;
if(deaph[now]==-1&&E[i].cost>0) {
q.push(now);
deaph[now]=deaph[x]+1;
}
}
}
return false;
}
int dfs(int s, int t,int flow)
{
if(s == t) {
return flow;
}
int ans = 0;
for(int i = head[s]; ~i; i = E[i].next) {
int &to = E[i].to, w = E[i].cost;
if(deaph[s] + 1 == deaph[to] && w > 0) {
int tmp = min(flow - ans, w);
int tf = dfs(to, t, tmp);
E[i].cost -= tf;
E[i^1].cost += tf;
ans += tf;
if(ans == flow) {
return ans;
}
}
}
return ans;
}
int Dinic(int s, int t)
{
int ret = 0;
while (bfs(s, t)) {
ret += dfs(s, t, INF);
}
return ret;
}
bool check(int x,int y) {
if(x>=1&&x<=m&&y>=1&&y<=n) return true;
return false;
}
int main() {
ios::sync_with_stdio(false);
cin >> m >> n;
init();
// Unit number 1~m
// Table No m+1~m+n
// Source point 0 Confluence n+m+1
int sum=0;
for(int i=1;i<=m;i++) {
cin >> flow;
sum+=flow;
add(0,i,flow);
}
for(int i=1;i<=n;i++) {
cin >> flow;
add(m+i,m+n+1,flow);
}
for(int i=1;i<=m;i++) {
for(int j=1;j<=n;j++) {
add(i,m+j,1);
}
}
int ans=Dinic(0,n+m+1);
if(ans!=sum) cout << 0 << endl;
else {
cout << 1 << endl;
for(int i=1;i<=m;i++) {
int flag=true;
for(int j=head[i];~j;j=E[j].next) {
if(!E[j].cost) {
if(flag) cout << E[j].to-m , flag=false;
else cout << " " << E[j].to-m;
}
}
cout << endl;
}
}
return 0;
}
边栏推荐
- Wechat applet custom tabbar
- Difference between map and object
- Mapstacks: data normalization and layered color layer loading
- Shell script
- I just purchased a MySQL database and prompted that there are already instances. The console login instance needs to provide a database account. How do I know the database account.
- Variable setting in postman
- Splicing audio files with ffmpeg-4.3
- Responsibility chain mode -- through interview
- 微信小程序自定义tabBar
- Enjoy yuan mode -- a large number of flying dragons
猜你喜欢
Appium introduction and environment installation
Read all text from stdin to a string
Design of routing service for multi Activity Architecture Design
红象云腾完成与龙蜥操作系统兼容适配,产品运行稳定
网络安全审查办公室对知网启动网络安全审查
Berkeley, MIT, Cambridge, deepmind and other industry leaders' online lectures: towards safe, reliable and controllable AI
Basic properties and ergodicity of binary tree
OSI notes sorting
Pytest test framework II
在Dialog中使用透明的【X】叉叉按钮图片
随机推荐
[performance tuning basics] performance tuning standards
How Fiddler works
Image panr
Analysis of errors in JSON conversion using objectmapper
It was Tencent who jumped out of the job with 26k. It really wiped my ass with sandpaper. It gave me a hand
JMeter basic learning records
Can the OPDS SQL component pass process parameters to the next component through context
Procedural life: a few things you should know when entering the workplace
A/b test helps the growth of game business
C语言实现扫雷(简易版)
OSI notes sorting
DHCP operation
使用gorm查询数据库时reflect: reflect.flag.mustBeAssignable using unaddressable value
I just purchased a MySQL database and prompted that there are already instances. The console login instance needs to provide a database account. How do I know the database account.
微信小程序自定义tabBar
Postman assertion
Design of routing service for multi Activity Architecture Design
全上链哈希游戏dapp系统定制(方案设计)
Shell script
Freshman girls' nonsense programming is popular! Those who understand programming are tied with Q after reading