zoj2532:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1532

题意:有n个发射点,m个中继站,然后发射点会发射一些信息给汇点0,这些信息可能会经过中继站,然后给出l条边,每一条都有一个信息容量,现在问你改变哪些边中的任意一条都可以改变这n个点发射信息到0点的总和。

题解:首先,分析一下,要改变的这一条边具有一下性质:

1 这一条边一定是满流的,

2边的起点应该属于残余网络的源点部分,

3边的终点应该是属于残余网络的汇点部分。

所以建图的时候,设置超级源点ss,然后与每个发射点连接,容量是INF,然后跑网络流,从源点深搜,再从汇点神搜,最后遍历每一边,看是否满足以上3条性质。

 #include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#define INF 100000000
using namespace std;
const int N=;
const int M=;
struct Node{
int v;
int f;
int next;
}edge[M];
int n,m,u,v,l,w,cnt,sx,ex;
int head[N],pre[N];
int ans[N],top;
int from[N],to[N];
bool vis1[N],vis2[N];
void init(){
cnt=;
memset(head,-,sizeof(head));
memset(vis1,,sizeof(vis1));
memset(vis2,,sizeof(vis2));
}
void add(int u,int v,int w,int id){
edge[cnt].v=v;
edge[cnt].f=w;
edge[cnt].next=head[u];
head[u]=cnt++;
edge[cnt].f=;
edge[cnt].v=u;
edge[cnt].next=head[v];
head[v]=cnt++;
}
bool BFS(){
memset(pre,,sizeof(pre));
pre[sx]=;
queue<int>Q;
Q.push(sx);
while(!Q.empty()){
int d=Q.front();
Q.pop();
for(int i=head[d];i!=-;i=edge[i].next ){
if(edge[i].f&&!pre[edge[i].v]){
pre[edge[i].v]=pre[d]+;
Q.push(edge[i].v);
}
}
}
return pre[ex]>;
}
int dinic(int flow,int ps){
int f=flow;
if(ps==ex)return f;
for(int i=head[ps];i!=-;i=edge[i].next){
if(edge[i].f&&pre[edge[i].v]==pre[ps]+){
int a=edge[i].f;
int t=dinic(min(a,flow),edge[i].v);
edge[i].f-=t;
edge[i^].f+=t;
flow-=t;
if(flow<=)break;
} }
if(f-flow<=)pre[ps]=-;
return f-flow;
}
void solve(){
int sum=;
while(BFS())
sum+=dinic(INF,sx);
}
void DFS1(int u,int fa){
if(vis1[u])return;
vis1[u]=;
for(int i=head[u];i!=-;i=edge[i].next){
if(edge[i].f>){
DFS1(edge[i].v,u);
}
}
}
void DFS2(int u,int fa){
if(vis2[u])return;
vis2[u]=;
for(int i=head[u];i!=-;i=edge[i].next){
if(edge[i^].f>){
DFS2(edge[i].v,u);
}
}
}
int main() {
while(~scanf("%d%d%d",&n,&m,&l)&&n) {
init();
for(int i=;i<=l;i++){
scanf("%d%d%d",&from[i],&to[i],&w);
add(from[i],to[i],w,i);
}
for(int i=;i<=n;i++){
add(m+n+,i,INF,);
}
sx=n+m+,ex=;
solve();
DFS1(sx,sx);
DFS2(ex,ex);
top=;
for(int i=;i<=l;i++){
int u=from[i],v=to[i];
if(vis1[u]&&vis2[v])
ans[++top]=i;
}
if(top==)puts("");
else{
sort(ans+,ans+top+);
for(int i=;i<top;i++)
printf("%d ",ans[i]);
printf("%d\n",ans[top]);
}
}
return ;
}

Internship的更多相关文章

  1. ZOJ 2532 Internship 求隔边

    Internship Time Limit: 5 Seconds      Memory Limit: 32768 KB CIA headquarter collects data from acro ...

  2. ZOJ 2532 Internship

    Internship Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original ID: ...

  3. ZOJ 1532 Internship (Dinic)

    看来模板又错了,敲你妈妈小饼干 #include<iostream> #include<queue> #include<cstring> #include<c ...

  4. Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 1)D. Frequency of String

    题意:有一个串s,n个串模式串t,问s的子串中长度最小的包含t k次的长度是多少 题解:把所有t建ac自动机,把s在ac自动机上匹配.保存每个模式串在s中出现的位置.这里由于t两两不同最多只有xsqr ...

  5. B - Internship (网络流关键割边)

    题目链接:https://cn.vjudge.net/contest/281961#problem/B 题目大意:给你n个城市,中间有一些中转站,然后给你终点,再给你l条轨道以及流量,问你增加哪几条轨 ...

  6. 面经:Bloomberg Internship第一轮

    上来先问了一个系统设计的问题,一个front end, 一个back end. front end有很多UI,一个UI对10个多customers,back end有许多processor,或者pro ...

  7. ZOJ 2532 Internship(最大流找关键割边)

    Description CIA headquarter collects data from across the country through its classified network. Th ...

  8. Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 2)

    A. Splits time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...

  9. zoj 2532 Internship【最小割】

    就是求哪些边在最大流上满流,也就是找割边.把0作为t点,s向所有的1~n连流量为inf的边,其他的边按照流量连.跑一遍最大流,从s顺着有残余流量的正向边dfs打标记fr,从t顺着正向边有残余流量的反向 ...

随机推荐

  1. oracle13 触发器 变量

    触发器   触发器是指隐含的执行的存储过程.当定义触发器时,必须要指定触发的事件和触发的操作,常用的触发事件包括insert,update,delete语句,而触发操作实际就是一个pl/sql块.可以 ...

  2. AFNetWorking源码详解(二)

    来源:Yuzeyang 链接:http://zeeyang.com/2016/03/15/AFNetWorking-two/ AFHTTPSessionManager继承于AFURLSessionMa ...

  3. Android开发全套视频教程在线观看网盘下载

    千锋金牌讲师老罗老师简介: 国内第一批Android教学讲师,10多年软件开发经验,6年多教学经验,曾担任广东电信北京分公司移动事业部项目经理,主持过微软中国平台考试系统.山西省旅游局智能化平台等大型 ...

  4. 超过2T,磁盘分区

    MBR:MBR分区表(即主引导记录)大家都很熟悉.所支持的最大卷:2T,而且对分区有限制:最多4个主分区或3个主分区加一个扩展分区 GPT: GPT(即GUID分区表).是源自EFI标准的一种较新的磁 ...

  5. javascript实现继承的6种方式

    /*1.原型链继承*/ function SuperType() { this.property = true; } SuperType.prototype.getSuperValue = funct ...

  6. css3之@font-face---再也不用被迫使用web安全字体了

    1,@font-face 的出现在没有css3之前,我们给网页设计字体只能设置web安全字体,使得我们的网页表现看上去好像都是那个样子,那么如果我们想给字体设置web设计者提供的字体呢?没有问题,cs ...

  7. bootstrap 笔记01

    bootstrap源码样式: 移除body的margin声明设置body的背景色为白色为排版设置了基本的字体.字号和行高设置全局链接颜色,且当链接处于悬浮“:hover”状态时才会显示下划线样式 1, ...

  8. 使用html5兼容低版本浏览器

    因为html5 新出的一些语义化的标签,在低版本浏览器下不能识别,举个例子,比如你写了一个 header 标签中,写了一段文本,在低版本浏览器下,肯定是能看到的,但是,那是他是不认识 header标签 ...

  9. [DEncrypt] Encrypt--加密/解密/MD5加密 (转载)

    点击下载  Encrypt.zip 这个类是关于加密,解密的操作,文件的一些高级操作1.Encrypt加密2.Encrypt解密3.Encrypt MD5加密看下面代码吧 /// <summar ...

  10. the account is currently locked out. The system administrator can unlock it.

    今天遇到的问题比较有意思.首先是很久没有打开测试数据库了,今天打开,使用service程序测试的时候出现下面的错误提示:Message: System.Data.SqlClient.SqlExcept ...