#include #include #include #include using namespace std; int cap[100][100]; int a[100]; int flow[100][100]; int path[1010]; int N,M; const int inf = 0x7f7f7f7f; int f; void BFS( ) { int i, j, k, t, u, v; f = 0; memset(flow, 0, sizeof(flow)); for (; ; ) { memset(a, 0, sizeof(a)); memset(path, 0, sizeof(path)); deque q; a[1] = inf; q.push_back(1); while (!q.empty( )) { t = q.front( ); q.pop_front( ); for (i = 0; i <= N; i++) if (!a[i] && flow[t][i] < cap[t][i] ) { path[i] = t; a[i] = min(a[t], cap[t][i] - flow[t][i]); q.push_back(i); } } if (a[N] == 0) break; for (u = N; u != 1; u = path[u]) { flow[path[u]][u] += a[N]; flow[u][path[u]] -= a[N]; } f += a[N]; } printf("%d\n",f); } int main( ) { int T, l = 0, i, b, c, d; scanf("%d", &T); while (T--) { l++; scanf("%d%d", &N, &M); memset(cap, 0, sizeof(cap)); for (i = 0; i < M; i++) { scanf("%d%d%d", &d, &b, &c); cap[d][b] += c; } printf("Case %d: ",l); BFS( ); } return 0; }