您的位置:首页 > 其它

USACO 4.4 Pollutant Control

2013-05-15 17:47 393 查看
第一二问,可以通过*1001+1,最后ans/1001 ans%1001来解决,第三问,看题解后完全无想法,然后找了一种水过的办法,水过了。。这种做法应该是错的。

/*
ID:cuizhe
LANG: C++
TASK: milk6
*/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;
#define LL long long
LL INF;
LL flow[201][201];
LL low[201];
int path[201],used[201];
int x[1001],y[1001];
int str,end,n,m;
LL bfs()
{
int t,i;
memset(path,-1,sizeof(path));
memset(used,0,sizeof(used));
used[str] = 1;
queue<int> que;
que.push(str);
low[str] = INF;
while(!que.empty())
{
t = que.front();
que.pop();
if(t == end) break;
for(i = 1; i <= n; i ++)
{
if(i != str&&!used[i]&&flow[t][i])
{
low[i] = low[t] < flow[t][i] ? low[t]:flow[t][i];
used[i] = 1;
path[i] = t;
que.push(i);
}
}
}
if(path[end] == -1)
return -1;
else
return low[end];
}
LL EK()
{
LL res,now,ans = 0;
while((res = bfs()) != -1)
{
ans += res;
now = end;
while(now != str)
{
flow[now][path[now]] += res;
flow[path[now]][now] -= res;
now = path[now];
}
}
return ans;
}
int main()
{
int i,sv,ev;
LL ans,w;
INF = (LL)9999999*9999999;
freopen("milk6.in","r",stdin);
freopen("milk6.out","w",stdout);
scanf("%d%d",&n,&m);
memset(flow,0,sizeof(flow));

for(i = 1; i <= m; i ++)
{
scanf("%d%d%lld",&sv,&ev,&w);
x[i] = sv;
y[i] = ev;
flow[sv][ev] += ((LL)(w*1001+1)*500000 + i-1);
}
str = 1,end = n;
ans = EK();
printf("%lld %lld\n",ans/500500000,(ans/500000)%1001);
for(i = 1;i <= m;i ++)
{
if(used[x[i]]&&!used[y[i]])
printf("%d\n",i);
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: