These two questions are related to Eulerian graph's judgment, one is the direction graph, the other is the Eulerian graph of the non-direction graph and there is a direction graph =
First Look at 10129 ... We see the first letter of the Word as the entry, the last character as a perceive, then the question becomes whether there is a Euler circuit in the graph. The criterion for judging the graph is that the graph is a connected graph and the maximum number of two points of the out degree is not equal to the degrees, in fact, the two points is the starting point and the end point, and must be one of the points of the degree of penetration is exactly 1 (as the end point), the other point of the degree is exactly 1 (as
Connected graphs we use and check the set to judge if the graph is a connected graph, then they share the ancestor =
#include <stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespacestd;intp[ -];Const intmaxn=100000;inta[ -],b[ -];Chars[ +];voidinit () { for(intI=0;i< -; i++) P[i]=i;}intFindintx) { returnP[x]==x?X:find (p[x]);}intMain () {intT,n; scanf ("%d",&t); while(t--) {init (); Memset (A,0,sizeof(a)); memset (b,0,sizeof(b)); scanf ("%d",&N); for(intI=0; i<n;i++) {scanf ("%s", s); int inch=s[0]-'a'; int out=s[strlen (s)-1]-'a'; a[inch]++; b[ out]++; if(Find (inch)!=find ( out)) P[find (inch)]=find ( out); } inti,j; intflag=1; for(i=0;! a[i]&&!b[i];i++); for(j=i+1;j< -; j + +) { if((a[j]| | B[J]) &&find (i)! =Find (j)) {Flag=0; Break; } } intCount=0; if(flag) {//printf ("pppp\n"); for(i=0;! a[i]&&!b[i];i++); for(j=i+1;j< -; j + +) { if(a[j]>B[j]) { if(a[j]-b[j]>1) {flag=0; Break; } ElseCount++; } Else if(b[j]>A[j]) { if(b[j]-a[j]>1) {flag=0; Break; } ElseCount++; } }} if(!flag| | Count>2) printf ("The door cannot be opened.\n"); Elseprintf ("Ordering is possible.\n"); } return 0;}
10054 the problem is to give an undirected graph and then let you judge that there is euler loop = =, if present, print any of the Euler loops, the judgment of the undirected graph is that the graph is a connected graph and there is no singularity vertex in the graph
Print the word from any point of departure, recursive output Path = =
#include <stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<stack>#include<queue>#include<vector>using namespacestd;Const intmaxn= -;intMP[MAXN][MAXN];intp[ -];intdir[ -];intF[MAXN];intN;structnode{intu,v;};voidinit () { for(intI=1; i<= -; i++) P[i]=i;}intFindintx) { returnP[x]==x?X:find (p[x]);}voidDfsintu) { intv; for(v=1; v<= -; v++) { if(mp[u][v]>0) {Mp[u][v]--; Mp[v][u]--; DFS (v); printf ("%d%d\n", v,u);//If you have a map, put the vertices in the stack first, and then start the output path from the top of the stack. } }}intMain () {intT,tt; intk=0; scanf ("%d",&t); for(tt=0; tt<t;tt++) { if(TT) printf ("\ n"); memset (dir,0,sizeof(dir)); Memset (MP,0,sizeof(MP)); Init (); scanf ("%d",&N); intb; for(intI=0; i<n;i++) {scanf ("%d%d",&a,&b); MP[A][B]++; Mp[b][a]++; Dir[a]++,dir[b]++; if(Find (a)! =find (b)) P[find (a)]=find (b); } printf ("Case #%d\n",++k); intnum=0; inti,j; intflag=1; for(i=1;! dir[i];i++); for(j=i+1; j<= -; j + +) { if(Dir[j]&&find (j)! =find (i)) {Flag=0; Break; } } if(flag) {intCount=0; for(j=i+1; j<= -; j + +) if(dir[j]&1) {flag=0; Break; } } if(!flag) {printf ("some beads may lost\n"); Continue; } intu; for(u=0;! dir[u];u++); DFS (U); } return 0;}
Uva (10129) +uva (10054)