Network flow judgment mixed Graph//through the network flow so that the points of the same degree of access possible, otherwise the weight of the impossible//residual network is the number of changes in the direction, that is, n two-way Edge has n times//time:157ms memory:348k# Include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <queue >using namespace std; #define MAXN 205#define INF 0x3f3f3f3fint n,m;int s,t;int dif[maxn];int RES[MAXN][MAXN]; Residual network-Represents the variable direction number int Pre[maxn];bool BFs () {memset (pre,-1,sizeof (pre)); Queue<int> Q; Q.push (s); Pre[s] = 0; while (!q.empty ()) {int cur = q.front (); Q.pop (); for (int i = 1; I <= t; i++) {if (pre[i] = = 1 && res[cur][i]) {Pre [I] = cur; if (i = = t) return true; Q.push (i); }}} return false;} int EK () {int maxflow = 0; while (BFS ()) {int mind = INF; for (int i = t; I! = s; i = pre[i]) mind = min (mind, res[pre[i]][i]); for (int i = t; i = s; i = Pre[i]) {res[pre[i]][i]-= mind; Res[i][pre[i] + + + mind; } Maxflow + = mind; } return maxflow;} int main () {//freopen ("In.txt", "R", stdin); int T; scanf ("%d", &t); while (t--) {memset (dif,0,sizeof (DIF)); memset (res,0,sizeof (res)); scanf ("%d%d", &n, &m); int total = 0; s = 0; t = n+1; for (int i = 0; i < m; i++) {int u,v,t; scanf ("%d%d%d", &u,&v,&t); dif[u]++; dif[v]--; if (t = = 0) res[u][v] + = 1; Heavy edge then variable direction +1} bool flag = TRUE; for (int i = 1; I <= n; i++) {if (Dif[i] > 0) {//out many-odd-through source points res[s][i] = dif[ I]/2; Total + = DIF[I]/2; } if (Dif[i] < 0) res[i][t] =-DIF[I]/2; In degrees-give odd-out if (ABS (Dif[i])% 2 = = 1) by meeting point {flag = false; Break }} (Flag && EK () = = TotAL)? printf ("possible\n"): printf ("impossible\n"); } return 0;}
Euler circuit determination of mixed graphs of ACM/ICPC-network flow (POJ1637)