Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include <bits/stdc++.h>using namespace std;const int N = 5005;const int M = 100005;const int inf = ~0u>>2;struct eg{int u, v, cap; //源点汇点流量eg(){}eg(int a, int b, int c){ u = a, v = b, cap = c; }}edg[M*4]; //边数开大int fir[N], nex[M*4], ecnt, s, t;void add(int a, int b, int c){edg[ecnt] = eg(a, b, c);nex[ecnt] = fir[a], fir[a] = ecnt++;edg[ecnt] = eg(b, a, 0); //反向边nex[ecnt] = fir[b], fir[b] = ecnt++;}int lev[N], q[N*4], top, tail;bool Bfs(int s, int t){memset(lev, -1, sizeof(lev));top = tail = 0;lev[s] = 0; q[tail++] = s;while( top < tail ){int u = q[top++];if( u == t ) return 1;for(int k = fir[u]; k != -1; k = nex[k]){int v = edg[k].v;if( edg[k].cap && lev[v] == -1){lev[v] = lev[u] + 1;q[tail++] = v;}