这题不是坑爹的么!!带宽,带宽不是双向的吗!现在我才反应过来那个alldirectional貌似是定向的意思。。。水题啊!!!!极度水!!灰常水!!你赢了zoj,再也不刷你了!!
ps:网络流也刷的差不多了,开始刷别的了!
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cassert>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 161;
const int s = 160;
struct zz
{
int from;
int to;
int c;
int id;
}zx,tz;
vector<zz>g[maxn];
queue<int>q;
int cen[maxn];
int se[maxn];
bool vis[maxn];
int x[maxn*maxn];
int y[maxn*maxn];
vector<int>v;
int n,m,l;
void link(int now,int to,int c,int bc)
{
zx.from = now;
zx.to = to;
zx.c = c;
zx.id = g[to].size();
g[now].push_back(zx);
swap(zx.from,zx.to);
zx.c = bc;
zx.id = g[now].size()-1;
g[to].push_back(zx);
return ;
}
bool bfs()
{
while(!q.empty())
{
q.pop();
}
memset(cen,-1,sizeof(cen));
q.push(s);
cen[s] = 0;
int now,to;
while(!q.empty())
{
now = q.front();
q.pop();
for(int i=0;i<g[now].size();i++)
{
to = g[now][i].to;
if(g[now][i].c > 0 && cen[to] == -1)
{
cen[to]=cen[now]+1;
q.push(to);
}
}
}
return cen[0] != -1;
}
int dfs(int flow = inf,int now = s)
{
if(now == 0)
{
return flow;
}
int temp,sum =0;
int to;
for(int i=0;i<g[now].size();i++)
{
to = g[now][i].to;
if(g[now][i].c>0 && flow>sum && cen[now]+1 == cen[to])
{
temp = dfs(min(flow-sum,g[now][i].c),to);
sum += temp;
g[now][i].c -= temp;
g[to][g[now][i].id].c += temp;
}
}
if(!sum) cen[now] = -1;
return sum;
}
void dinic()
{
while(bfs())
{
dfs();
}
return ;
}
void bfss()
{
while(!q.empty())
{
q.pop();
}
memset(se,0,sizeof(se));
memset(vis,false,sizeof(vis));
q.push(s);
vis[s] = true;
se[s] = 1;
int now,to;
while(!q.empty())
{
now = q.front();
q.pop();
for(int i=0;i<g[now].size();i++)
{
to = g[now][i].to;
if(g[now][i].c > 0)
{
se[to] = 1;
if(!vis[to])
{
vis[to] = true;
q.push(to);
}
}
}
}
return ;
}
void bfst()
{
while(!q.empty())
{
q.pop();
}
memset(vis,false,sizeof(vis));
vis[0] = true;
se[0] = 2;
q.push(0);
int now,from,id;
while(!q.empty())
{
now = q.front();
q.pop();
for(int i=0;i<g[now].size();i++)
{
id = g[now][i].id;
from = g[now][i].to;
if(g[from][id].c > 0)
{
se[from] = 2;
if(!vis[from])
{
vis[from] = true;
q.push(from);
}
}
}
}
return ;
}
void zz1215()
{
dinic();
bfss();
bfst();
v.clear();
for(int i=1;i<=l;i++)
{
if(se[x[i]] == 1 && se[y[i]]==2)
{
v.push_back(i);
}
}
if(v.empty())
{
cout<<endl;
}
else
{
cout<<v[0];
for(int i=1;i<v.size();i++)
{
cout<<" "<<v[i];
}
cout<<endl;
}
return ;
}
int main()
{
while(cin>>n)
{
if(n==0)
{
break;
}
cin>>m>>l;
for(int i=0;i<maxn;i++)
{
g[i].clear();
}
int c;
for(int i=1;i<=l;i++)
{
cin>>x[i]>>y[i]>>c;
link(x[i],y[i],c,0);
}
for(int i=1;i<=n;i++)
{
link(s,i,inf,0);
}
zz1215();
}
return 0;
}
分享到:
相关推荐
POJ第1861题源码 POJ第1861题源码 POJ第1861题源码
poj2009离线题库 poj2009离线题库
北京大学在线测评网站POJ第1200题的解答,已经AC通过
poj2009离线题库 poj2009离线题库
poj部分水题代码描述,为初学者提供一些必要的基础
poj上面的300道AC题,c++源码,自己写的不会有任何问题。
poj训练 c语言poj训练 西工大 poj 100题。
POJ ACM一些题的代码和总结。还有POJ用到JAVA的简单介绍。
POJ 1328 java做!雷达问题!java版本!AC答案~
初学acmer必练题,包括图论,动态规划,和数论的基础题
POJ推荐50题 练练不妨 网上看到就弄了来。
北大POJ第1005题答案(C语言)
POJ题目源码 共221题 含源码,题目和简单的分类
POJ各题算法分类和题目推荐 ACM必看 POJ各题算法分类和题目推荐 ACM必看 POJ各题算法分类和题目推荐 ACM必看
北大POJ水题整合包 解题报告+AC代码
北大 POJ的水题解答C++版,请合理使用
北京大学Online judge 第2251题 POJ2251
本人在POJ上第1922题用C++做的程序设计,可供参考。
poj题目,需要可以下载,虽然没有包含所有的题目,但是对初级入门有帮助
POJ100题详细解题报告