USACO 4.4 Pollutant Control
2013-05-15 17:47
393 查看
第一二问,可以通过*1001+1,最后ans/1001 ans%1001来解决,第三问,看题解后完全无想法,然后找了一种水过的办法,水过了。。这种做法应该是错的。
View Code
/* 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
相关文章推荐
- Pollutant Control_usaco 4.4_网络流
- 洛谷 P1344 [USACO4.4]追查坏牛奶Pollutant Control
- P1344 [USACO4.4] 追查坏牛奶Pollutant Control
- USACO 4.4 Pollutant Control (网络流求最小割割集)
- USACO 4.4 Pollutant Control
- 求割边最少的最小割(P1344 [USACO4.4]追查坏牛奶Pollutant Control)
- 洛谷P1344 [USACO4.4]追查坏牛奶Pollutant Control(网络流, 最大流最小割)
- USACO Section 4.4 Pollutant Control
- usaco training 4.4.2 Pollutant Control 追查坏牛奶 题解
- usaco Pollutant Control
- usaco 4.4.2 Pollutant Control
- USACO 4.4.2 Pollutant Control追查坏牛奶 题解与分析
- USACO Section 4.4 Pollutant Control - 找更优的搜索枚举方案~
- [USACO4.4.2 Pollutant Control]
- usaco Pollutant Control
- USACO Pollutant Control 解题报告
- usaco-4.4-shutter-passed
- usaco 4.4 Frame Up 2010.8.8
- Pollutant Control
- USACO 4.4 Frame Up(拓扑排序)