structEdge{ int from; int to; int flow; int cap; Edge(int f, int t, int fl, int c){ from = f; to = t; cap = c; flow = fl; } };
int p, n; int in[M][10], out[M][10]; vector<Edge> edges; vector<int> head[M], prefix[M]; int deep[M], num[M], cur[M], pre[M];
voidadd(int from, int to, int cap){ edges.push_back(Edge(from, to, 0, cap)); edges.push_back(Edge(to, from, 0, 0)); int sz = edges.size(); head[from].push_back(sz-2); head[to].push_back(sz-1); }
voidbfs(int s, int t){ memset(deep, -1, sizeof(deep)); memset(num, 0, sizeof(num)); queue<int> q; q.push(s); deep[s] = 0; num[deep[s]]++; while(!q.empty()){ int cur = q.front(); q.pop(); for(int i = 0; i < prefix[cur].size(); i++){ int to = prefix[cur][i]; if(deep[to] < 0){ deep[to] = deep[cur] + 1; num[deep[to]]++; q.push(to); } } } }