USACO 4.4 Pollutant Control

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

 1 /*
 2  ID:cuizhe
 3  LANG: C++
 4  TASK: milk6
 5  */
 6 #include <cstdio>
 7 #include <cstring>
 8 #include <cmath>
 9 #include <queue>
10 using namespace std;
11 #define LL long long
12 LL INF;
13 LL flow[201][201];
14 LL low[201];
15 int path[201],used[201];
16 int x[1001],y[1001];
17 int str,end,n,m;
18 LL bfs()
19 {
20     int t,i;
21     memset(path,-1,sizeof(path));
22     memset(used,0,sizeof(used));
23     used[str] = 1;
24     queue<int> que;
25     que.push(str);
26     low[str] = INF;
27     while(!que.empty())
28     {
29         t = que.front();
30         que.pop();
31         if(t == end) break;
32         for(i = 1; i <= n; i ++)
33         {
34             if(i != str&&!used[i]&&flow[t][i])
35             {
36                 low[i] = low[t] < flow[t][i] ? low[t]:flow[t][i];
37                 used[i] = 1;
38                 path[i] = t;
39                 que.push(i);
40             }
41         }
42     }
43     if(path[end] == -1)
44         return -1;
45     else
46         return low[end];
47 }
48 LL EK()
49 {
50     LL res,now,ans = 0;
51     while((res = bfs()) != -1)
52     {
53         ans += res;
54         now = end;
55         while(now != str)
56         {
57             flow[now][path[now]] += res;
58             flow[path[now]][now] -= res;
59             now = path[now];
60         }
61     }
62     return ans;
63 }
64 int main()
65 {
66     int i,sv,ev;
67     LL ans,w;
68     INF = (LL)9999999*9999999;
69     freopen("milk6.in","r",stdin);
70     freopen("milk6.out","w",stdout);
71     scanf("%d%d",&n,&m);
72     memset(flow,0,sizeof(flow));
73 
74     for(i = 1; i <= m; i ++)
75     {
76         scanf("%d%d%lld",&sv,&ev,&w);
77         x[i] = sv;
78         y[i] = ev;
79         flow[sv][ev] += ((LL)(w*1001+1)*500000 + i-1);
80     }
81     str = 1,end = n;
82     ans = EK();
83     printf("%lld %lld\n",ans/500500000,(ans/500000)%1001);
84     for(i = 1;i <= m;i ++)
85     {
86         if(used[x[i]]&&!used[y[i]])
87         printf("%d\n",i);
88     }
89     return 0;
90 }
View Code

 

posted @ 2013-05-15 17:47  Naix_x  阅读(179)  评论(0编辑  收藏  举报