Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
牛人给组数据吧,错的不行了!#include <stdio.h> #include <string.h> #include <stdlib.h> #define M 100000 int i, j, n, m, deq[M], pre[M], c[202][202], f[202][202], minnum[M], map[202][202], visit[202]; int bfs() { deq[0] = 1; pre[0] = -1; visit[1] = 1; minnum[0] = 2000000000; int tail = 1, min; for (i = 0; i < tail; i++) { for (j = m; j >= 1; j--) { if (visit[j] == 0 && map[deq[i]][j] && c[deq[i]][j]-f[deq[i]][j] > 0) { deq[tail] = j; pre[tail] = i; visit[j] = 1; if (c[deq[i]][j]-f[deq[i]][j] < minnum[i]) minnum[tail] = c[deq[i]][j]-f[deq[i]][j]; else minnum[tail] = minnum[i]; if (j == m) { min = minnum[tail]; while (pre[tail] != -1) { f[deq[pre[tail]]][deq[tail]] += min; f[deq[tail]][deq[pre[tail]]] -= min; tail = pre[tail]; } return min; } tail++; } } } return 0; } int main() { int i, ans, tmpnum, n1, n2; while (scanf("%d %d", &n, &m) != EOF) { memset(c, 0, sizeof(c)); memset(map, 0, sizeof(map)); for (i = 0; i < n; i++) { scanf("%d %d", &n1, &n2); map[n1][n2] = 1; scanf("%d", &tmpnum); c[n1][n2] += tmpnum; } memset(f, 0, sizeof(f)); ans = 0; while (1) { memset(visit, 0, sizeof(visit)); tmpnum = bfs(); if (tmpnum == 0) break; ans += tmpnum; } printf("%d\n", ans); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator