P3254 圆桌问题

 #include <bits/stdc++.h>
using namespace std;
const int maxn = , inf = 0x3f3f3f;
struct Edge {
int from, to, cap, flow;
}; struct Dinic {
int n, m, s, t;
vector<Edge> edges;
vector<int> G[maxn];
bool vis[maxn];
int d[maxn];
int cur[maxn]; void AddEdge(int from, int to, int cap) {
edges.push_back((Edge){from, to, cap, });
edges.push_back((Edge){to, from, , });
m = edges.size();
G[from].push_back(m-);
G[to].push_back(m-);
}
bool bfs() {
memset(vis, , sizeof(vis));
queue<int> que;
que.push(s);
d[s] = ;
vis[s] = true;
while (!que.empty()) {
int x = que.front(); que.pop();
for (int i = ; i < G[x].size(); ++i) {
Edge& e = edges[G[x][i]];
if (!vis[e.to] && e.cap > e.flow) {
vis[e.to] = true;
d[e.to] = d[x] + ;
que.push(e.to);
}
}
}
return vis[t];
}
int dfs(int x, int a) {
if (x == t || a == ) return a;
int flow = , f;
for (int& i = cur[x]; i < G[x].size(); ++i) {
Edge& e = edges[G[x][i]];
if (d[x] + == d[e.to] && (f = dfs(e.to, min(a, e.cap-e.flow))) > ) {
e.flow += f;
edges[G[x][i]^].flow -= f;
flow += f;
a -= f;
if (a == ) break;
}
}
return flow;
}
int maxflow(int s, int t) {
this->s = s; this->t = t;
int flow = ;
while (bfs()) {
memset(cur,,sizeof(cur));
flow += dfs(s,inf);
}
return flow;
}
}dinic; int r[maxn], c[maxn];
int main() {
int m, n; scanf("%d%d",&m,&n);
int s = m+n+, t = m+n+, sum = ;
for (int i = ; i <= m; ++i) {
scanf("%d",&r[i]);
sum += r[i];
}
for (int i = ; i <= n; ++i) scanf("%d",&c[i]); for (int i = ; i <= m; ++i) {
dinic.AddEdge(s,i,r[i]);
}
for (int i = ; i <= n; ++i) {
dinic.AddEdge(i+m,t,c[i]);
}
for (int i = ; i <= m; ++i) {
for (int j = ; j <= n; ++j) {
dinic.AddEdge(i,j+m,);
}
}
int ans = dinic.maxflow(s,t);
if (ans != sum) puts("");
else {
puts("");
for (int i = ; i <= m; ++i) {
for (int j = ; j < dinic.edges.size(); ++j) {
if (dinic.edges[j].from == i && dinic.edges[j].flow == ) {
printf("%d ",dinic.edges[j].to-m);
}
}
putchar('\n');
}
}
return ;
}

P3254 圆桌问题 网络流的更多相关文章

  1. 洛谷P3254 圆桌问题 网络流_二分图

    Code: #include<cstdio> #include<algorithm> #include<vector> #include<queue> ...

  2. 网络流之P3254 圆桌问题

    题目描述 假设有来自m 个不同单位的代表参加一次国际会议.每个单位的代表数分别为ri (i =1,2,……,m). 会议餐厅共有n 张餐桌,每张餐桌可容纳ci (i =1,2,……,n)个代表就餐. ...

  3. Luogu P3254 圆桌问题(最大流)

    P3254 圆桌问题 题面 题目描述 假设有来自 \(m\) 个不同单位的代表参加一次国际会议.每个单位的代表数分别为 \(r_i (i =1,2,--,m)\) . 会议餐厅共有 \(n\) 张餐桌 ...

  4. LibreOJ 6004. 「网络流 24 题」圆桌聚餐 网络流版子题

    #6004. 「网络流 24 题」圆桌聚餐 内存限制:256 MiB时间限制:5000 ms标准输入输出 题目类型:传统评测方式:Special Judge 上传者: 匿名 提交提交记录统计讨论测试数 ...

  5. P3254 圆桌问题

    题目链接 非常简单的一道网络流题 我们发现每个单位的人要坐到不同餐桌上,那也就是说每张餐桌上不能有同一单位的人.这样的话,我们对于每个单位向每张餐桌连一条边权为1的边,表示同一餐桌不得有相同单位的人. ...

  6. [cogs729] [网络流24题#5] 圆桌聚餐 [网络流,最大流,多重二分图匹配]

    建图:从源点向单位连边,边权为单位人数,从单位向圆桌连边,边权为1,从圆桌向汇点连边,边权为圆桌容量. #include <iostream> #include <algorithm ...

  7. 洛谷 [P3254] 圆桌问题

    简单最大流建图 #include <iostream> #include <cstdio> #include <cstring> #include <cmat ...

  8. Luogu P3254 圆桌问题

    题目链接 \(Click\) \(Here\) 水题.记得记一下边的流量有没有跑完. #include <bits/stdc++.h> using namespace std; const ...

  9. 洛谷P3254 圆桌问题(最大流)

    传送门 一道良心啊……没那么多麻烦了…… 从$S$向所有单位连边,容量为单位人数,从所有桌子向$T$连边,容量为桌子能坐的人数,从每一个单位向所有桌子连边,容量为$1$,然后跑一个最大流,看一看$S$ ...

随机推荐

  1. 2019-2020-1 20199326《Linux内核原理与分析》第八周作业

    可执行程序工作原理## 编译链接的过程### 示例程序hello.c #include<stdio.h> void main() { printf("Hello world\n& ...

  2. 2019-2020-1 20199326《Linux内核原理与分析》第三周作业

    第三周学习内容 庖丁解牛Linux内核分析第二章:操作系统是如何工作的 Linux内核分析实验二 学到的一些知识 计算机的三大法宝:存储程序计算机,函数调用堆栈,中断 堆栈是C语言程序运行时必须使用的 ...

  3. 计算机网络 之 Cisco packet tracer 的安装及汉化

    可以去官网下载最新版本的Cisco packet tracer 免费 汉化包及7.1版本百度云链接:链接: https://pan.baidu.com/s/1XudelgnMu6XysCZ36csl7 ...

  4. 模块sys,os

    Python的强大之处在于他有非常丰富和强大的标准库和第三方库,几乎你想实现的任何功能都有相应的Python库支持,以后的课程中会深入讲解常用到的各种库,现在,我们先来象征性的学2个简单的. 在Pyt ...

  5. BlackNurse攻击:4Mbps搞瘫路由器和防火墙

    研究人员宣称,最新的知名漏洞BlackNurse,是一种拒绝服务攻击,能够凭借仅仅15到18Mbps的恶意ICMP数据包就将防火墙和路由器干掉. 该攻击会滥用Internet控制报文协议(ICMP)第 ...

  6. JavaWEB开发时FCKeditor类似office界面的ajax框架,加入后就能做界面类似office,能进行简单的文本编辑操作+配置手册...

    2019独角兽企业重金招聘Python工程师标准>>> FCKeditor是一款功能强大的开源在线文本编辑器(DHTML editor),它使你在web上可以使用类似微软Word 的 ...

  7. Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine) B. Homecoming

    After a long party Petya decided to return home, but he turned out to be at the opposite end of the ...

  8. 疯子的算法总结14--ST算法(区间最值)

    借助倍增和动态规划可以实现O(1)的时间复杂度的查询 预处理: ①区间DP   转移方程  f[i][j] = min(MAX同理)(f[i][j - 1],f[i + ][j - 1])  f[i] ...

  9. pycharm 新建文件后选错文件格式怎么改

    经常在新建文件的时候,忘记填写文件后缀,导致文件无默认格式,而且同名字的文件怎么改都改不成想要的格式,所以随手记录一下怎么修正: 原因:肯定是pycharm已经默认指定了一个格式,所以再重复新建同样名 ...

  10. 学习HTML

    前端三剑客:HTML.CSS.JavaScript.现在就开始学习HTML啦. 学习资源:http://www.freecodecamp.cn/ 学习笔记: h1,head1,一级标题 <h1& ...