ZOJ 2532 Internship
Internship
This problem will be judged on ZJU. Original ID: 2532
64-bit integer IO format: %lld Java class name: Main
CIA headquarter collects data from across the country through its classified network. They have been using optical fibres long before it's been deployed on any civilian projects. However they are still under a lot pressure recently because the data are growing rapidly. As a result they are considering upgrading the network with new technologies that provide a few times wider bandwidth. In the experiemental stage, they would like to upgrade one segment of their original network in order to see how it performs. And as a CIA intern it's your responsibility to investigate which segment could actually help increase the total bandwidth the headquarter receives, suppose that all the cities have infinite data to send and the routing algorithm is optimized. As they have prepared the data for you in a few minutes, you are told that they need the result immediately. Well, practically immediately.
Input
Input contains multiple test cases. First line of each test case contains three integers n, m and l, they represent the number of cities, the number of relay stations and the number of segments. Cities will be referred to as integers from 1 to n, while relay stations use integers from n+1 to n+m. You can saves assume that n + m <= 100, l <= 1000 (all of them are positive). The headquarter is identified by the integer 0.
The next l lines hold a segment on each line in the form of a b c, where a is the source node and b is the target node, while c is its bandwidth. They are all integers where a and b are valid identifiers (from 0 to n+m). c is positive. For some reason the data links are all directional.
The input is terminated by a test case with n = 0. You can safely assume that your calculation can be housed within 32-bit integers.
Output
For each test print the segment id's that meets the criteria. The result is printed in a single line and sorted in ascending order, with a single space as the separator. If none of the segment meets the criteria, just print an empty line. The segment id is 1 based not 0 based.
Sample Input
2 1 3
1 3 2
3 0 1
2 0 1
2 1 3
1 3 1
2 3 1
3 0 2
0 0 0
Sample Output
2 3
<hey here is an invisible empty line>
Source
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct arc{
int to,flow,next;
arc(int x = ,int y = ,int z = -){
to = x;
flow = y;
next = z;
}
}e[maxn*maxn];
int head[maxn],cur[maxn],color[maxn],d[maxn],tot,S,T;
void add(int u,int v,int flow){
e[tot] = arc(v,flow,head[u]);
head[u] = tot++;
e[tot] = arc(u,,head[v]);
head[v] = tot++;
}
bool bfs(){
queue<int>q;
memset(d,-,sizeof(d));
d[S] = ;
q.push(S);
while(!q.empty()){
int u = q.front();
q.pop();
for(int i = head[u]; ~i; i = e[i].next){
if(e[i].flow && d[e[i].to] == -){
d[e[i].to] = d[u] + ;
q.push(e[i].to);
}
}
}
return d[T] > -;
}
int dfs(int u,int low){
if(u == T) return low;
int tmp = ,a;
for(int &i = cur[u]; ~i; i = e[i].next){
if(e[i].flow && d[e[i].to] == d[u] + &&(a=dfs(e[i].to,min(low,e[i].flow)))){
e[i].flow -= a;
e[i^].flow += a;
low -= a;
tmp += a;
if(!low) break;
}
}
if(!tmp) d[u] = -;
return tmp;
}
int dinic(){
int ans = ;
while(bfs()){
memcpy(cur,head,sizeof(head));
ans += dfs(S,INF);
}
return ans;
}
void dfs2(int u,int v){
color[u] = v;
for(int i = head[u]; ~i; i = e[i].next){
if(v == && e[i].flow && !color[e[i].to]) dfs2(e[i].to,v);
if(v == && e[i^].flow && !color[e[i].to]) dfs2(e[i].to,v);
}
}
int main(){
int N,M,L,x[],y[],tmp;
while(scanf("%d %d %d",&N,&M,&L),N||M||L){
memset(head,-,sizeof(head));
memset(color,,sizeof(color));
tot = T = ;
S = N + M + ;
for(int i = ; i <= N; ++i) add(S,i,INF);
for(int i = ; i < L; ++i){
scanf("%d %d %d",x+i,y+i,&tmp);
add(x[i],y[i],tmp);
}
dinic();
dfs2(S,);
dfs2(T,);
bool flag = false;
for(int i = ; i < L; ++i){
if(color[x[i]] == && color[y[i]] == ){
if(flag) putchar(' ');
printf("%d",i+);
flag = true;
}
}
putchar('\n');
}
return ;
}
ZOJ 2532 Internship的更多相关文章
- ZOJ 2532 Internship 求隔边
Internship Time Limit: 5 Seconds Memory Limit: 32768 KB CIA headquarter collects data from acro ...
- ZOJ 2532 Internship(最大流找关键割边)
Description CIA headquarter collects data from across the country through its classified network. Th ...
- zoj 2532 Internship【最小割】
就是求哪些边在最大流上满流,也就是找割边.把0作为t点,s向所有的1~n连流量为inf的边,其他的边按照流量连.跑一遍最大流,从s顺着有残余流量的正向边dfs打标记fr,从t顺着正向边有残余流量的反向 ...
- ZOJ 1532 Internship (Dinic)
看来模板又错了,敲你妈妈小饼干 #include<iostream> #include<queue> #include<cstring> #include<c ...
- ZOJ 2532 网络流最小割
求最小割的问题. 题意:已知网络中有n个源点,m的中转站(也就是节点),一个汇点(编号为0).给出网络,求一些边(增大这个边就可以增大汇点流量的边). 思路:一开始代码只找了有流=0就加入输出数组的情 ...
- [转] POJ图论入门
最短路问题此类问题类型不多,变形较少 POJ 2449 Remmarguts' Date(中等)http://acm.pku.edu.cn/JudgeOnline/problem?id=2449题意: ...
- Soj题目分类
-----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...
- 图论常用算法之一 POJ图论题集【转载】
POJ图论分类[转] 一个很不错的图论分类,非常感谢原版的作者!!!在这里分享给大家,爱好图论的ACMer不寂寞了... (很抱歉没有找到此题集整理的原创作者,感谢知情的朋友给个原创链接) POJ:h ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
随机推荐
- Android中的跨进程通信方法实例及特点分析(一):AIDL Service
转载请注明出处:http://blog.csdn.net/bettarwang/article/details/40947481 近期有一个需求就是往程序中增加大数据的採集点,可是由于我们的Andro ...
- redis作为缓存场景使用,内存耗尽时,突然出现大量的逐出,在这个逐出的过程中阻塞正常的读写请求,导致 redis 短时间不可用
redis 突然大量逐出导致读写请求block 内容目录: 现象 背景 原因 解决方案 ref 现象 redis作为缓存场景使用,内存耗尽时,突然出现大量的逐出,在这个逐出的过程中阻塞正常的读写请 ...
- django 笔记5 外键 ForeignKey
class UsserGroup(models.Model): uid = models.AutoField(primary_key=True) caption = models.CharField( ...
- [POJ2728] Desert King 解题报告(最优比率生成树)
题目描述: David the Great has just become the king of a desert country. To win the respect of his people ...
- IIS 7.5 配置
安装 MVC 3 对应版本. 或者对应的版本. 登陆时候报错 检查下面几项是否配置正确 检查ASP.net 是否开启. 检查网站的应用池是否配置正确 在处理程序映射当中检查这几项是否配置正确 如果都配 ...
- css inline-block列表布局
一.使用inline-block布局 二.多列布局方法二 <html><head> <meta charset="utf-8"> <tit ...
- Linux 设置交换分区
当需要添加swap分区时,可以使用如下方法:设置交换分区:1 以dd指令建立swapoff2 mkswap 来将swapfile 格式化为swap的档案格式.3 swapon 来启动该系统文件,使之成 ...
- 运行npm start vue.js项目 出现 npm ERR! missing script: start 错误
npm ERR! missing script: start 错误 有可能缺少依赖包,运行nmp install安装依赖(一般都依赖很多包,过程有点慢),安装完后发现多一个 node_modules文 ...
- HDU-1789 Doing Homework again 贪心问题 有时间限制的最小化惩罚问题
题目链接:https://cn.vjudge.net/problem/HDU-1789 题意 小明有一大堆作业没写,且做一个作业就要花一天时间 给出所有作业的时间限制,和不写作业后要扣的分数 问如何安 ...
- MySql系列之单表查询
单表查询的语法 SELECT 字段1,字段2... FROM 表名 WHERE 条件 GROUP BY field HAVING 筛选 ORDER BY field LIMIT 限制条数 关键字的执行 ...