The basic knowledge of Euler loops is stamped here
Mixed graph: Is the picture inside some side is has the direction edge, some edge is the non-direction edge, the composition diagram is called the mixed graph.
To determine whether the mixed graph satisfies the Euler circuit, the first must satisfy the Eulerian graph condition
1: The Euler circuit requires that all points have an even number of degrees, and Euler roads require an odd number of degrees for all points two.
2: To the direction of the non-directional, first arbitrary orientation, these will be the network flow between the building from the to the capacity of 1, and then for the current penetration is greater than the degree of the point Y, indicating that there is D = (degrees-out)/2 of the edge needs to become the opposite direction, we do not change to, but with a Give it a Y to T and a capacity of D.
Then for the point X with the current exit greater than the in degree, it is stated that the side with D = (out-of-the-in)/2 needs to be in the opposite direction, we do not make a change here, but instead use a network stream of the super source S, to its edge s to X, the capacity is D.
In this way, running a network flow, if full flow, it means that the degree of penetration is greater than the degree and the degree of greater than the flow between the degrees into the opposite direction, is a Eulerian graph.
For example title: hdoj3472 HS BDC
is to judge the mixed-graph Euler circuit, but the graph also has to judge the connectivity of the graph.
Simplified only the Unicom version can see nyoj99 word stitching also compare test code
AC Code:
#include <iostream>#include <string.h>#include <math.h>#include <queue>#include <algorithm>#include <stdlib.h>#include <map>#include <set>#include <stdio.h>#include <vector>using namespace STD;#define Del (A, B) memset (A,b,sizeof (a) )Const intN =1020;Const intINF =0x3f3f3f3f;structedge{intFrom,to,cap,flow;};structdinic{intN,m,s,t; vector<Edge>Edges vector<int>G[n];BOOLVis[n];intD[n],cur[n];voidInitintN) { This->n=n; for(intI=0; i<=n;i++) g[i].clear (); Edges.clear (); }voidAddedge (intFromintTo,intCAP) {//Build sideEdges.push_back (Edge) {from,to,cap,0}); Edges.push_back (Edge) {to,from,0,0}); M=edges.size (); G[from].push_back (M-2); G[to].push_back (M-1); }BOOLBFS () {Del (Vis,0); Queue<int>Q Q.push (s); d[s]=0; vis[s]=1; while(!q.empty ()) {intX=q.front (); Q.pop (); for(intI=0; I<g[x].size (); i++) {Edge &e =edges[g[x][i]];if(!vis[e.to] && e.cap>e.flow) {vis[e.to]=1; d[e.to]=d[x]+1; Q.push (e.to); } } }returnVIS[T]; }intDFS (intXintA) {if(X==t | | a==0)returnAintflow=0, F; for(int& I=cur[x];i<g[x].size (); i++) {Edge & e = edges[g[x][i]];if(d[x]+1= = D[e.to] && (F=dfs (E.to,min (a,e.cap-e.flow)) >0) {e.flow+=f; edges[g[x][i]^1].flow-= f; Flow+=f; A-=f;if(a==0) Break; } }returnFlow }intMax_flow (intSintT) { This->s=s; This->t=t;intflow=0; while(BFS ()) {Del (cur,0); Flow+=dfs (S,inf); }returnFlow }voidPrint () { for(intI=0; I<edges.size (); i++)printf("%c%c%d\n", edges[i].from+' A ', edges[i].to+' A ', Edges[i].cap); }};D inic solve;intin[ -];BOOLok[ -];BOOLmp[ -][ -];voidDfsintx) { for(intI=0;i< -; i++)if(ok[i]==true&& Mp[x][i]) {Ok[i] =false; DFS (i); }}intS,tt,ans;BOOLYougth () {Del (in,0), Del (OK,false), Del (MP,false); Solve.init ( -);intNscanf("%d", &n);intSS =0, TT =0, cnt =0; S = -, TT = -, ans =0; for(intI=0; i<n; i++) {stringSintZCin>>s>>z;intone = s[0]-' A ', double = s[s.size ()-1]-' A '; in[one]--; in[two]++; Ok[one] = Ok[two] =true; Mp[one][two] =true; SS = one;if(z==1) {Mp[two][one] =true; Solve. Addedge (One,two,1); } } for(intI=0;i< -; i++) {if(in[i]%2) {cnt++;if(in[i]<0) {ss = i; }Else if(in[i]>0) TT = i; } }if(cnt==0|| cnt==2) {DFS (ss); OK[SS] =false; for(intI=0;i< -; i++)if(ok[i]==true)return false;if(cnt==2) {in[ss]++;in[tt]--; Solve. Addedge (TT,SS,1);/// note opposite side} }Else return false; for(intI=0;i< -; i++) {if(in[i]<0) {solve. Addedge (s,i,-in[i]/2); }Else if(in[i]>0) {solve. Addedge (i,tt,in[i]/2); ans+=in[i]/2; } }return true;}intMain () {//freopen ("Input.txt", "R", stdin); intTscanf("%d", &t); for(intCAS =1; cas<=t;cas++) {printf("Case%d:", CAs);if(Yougth ()) {intFlow = Solve.max_flow (S,TT);if(flow = = ans)puts("Well done!");Else puts("1Poor boy!"); }Else puts("Poor boy!"); }return 0;}
Mixed-graph Euro-pull circuit (hdoj3472 HS BDC)