当前位置:网站首页>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;
}
边栏推荐
- Background operation retry gave up; KeeperErrorCode = ConnectionLoss
- Set up your own website (14)
- Time standard and format
- Learn to use a new technology quickly
- Undo log and redo log must be clear this time
- Procedural life: a few things you should know when entering the workplace
- 科创人·味多美CIO胡博:数字化是不流血的革命,正确答案藏在业务的田间地头
- Smooth live broadcast | analysis of key technologies for live broadcast pain points
- Appium desktop introduction
- The AI for emotion recognition was "harbouring evil intentions", and Microsoft decided to block it!
猜你喜欢

I feel that I am bald again when I help my children with their homework. I feel pity for my parents all over the world

A/b test helps the growth of game business

Interpreter mode -- formulas for dating

Sequential stack traversal binary tree

Basic properties and ergodicity of binary tree

JMeter response assertion

After a few years in the testing industry, do you still know a little?

After 5 months' test, it took 15K to come for an interview. When I asked, it was not worth even 5K. It was really

Image panr

Basic concepts and definitions of Graphs
随机推荐
JMeter basic learning records
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.
Visitor model -- generation gap between young and middle-aged people
Variable setting in postman
regular expression
伯克利、MIT、剑桥、DeepMind等业内大佬线上讲座:迈向安全可靠可控的AI
Rename and delete files
List set Introduction & common methods
Nifi fast authentication configuration
The four stages of cloud computing development have finally been clarified
Create a multithreaded thread class
What are the problems with traditional IO? Why is zero copy introduced?
Handling of garbled JMeter response data - three solutions
NPM download speed is slow
Builder mode -- Master asked me to refine pills
Difference between map and object
JMeter response assertion
After screwing the screws in the factory for two years, I earned more than 10000 yuan a month by "testing" and counterattacked
OSI notes sorting
Smooth live broadcast | analysis of key technologies for live broadcast pain points