Test instructions: Give n words, ask whether the N-word can be the end of the solitaire, that can constitute the Euler road
Follow the purple Book of Ideas: use and check the set to do, take the first letter of each word, and the last letter to do and check the operation of the set
But the title is Euler's road (excerpt from http://blog.csdn.net/hcbbt/article/details/9316301)
About the Europa Road (from titanium):
Determine if there is a Euclidean path to the graph
1. Determine the Jhoira of the graph (that is, the graph into undirected graph) connectivity, with a simple DFS. If the graphs are not connected, there must be no Euler road.
2. On the basis of the condition 1 for the Euler circuit, the requirements of a little, all points in the degree of equal to the degree, then there is the Euler circuit
For the Euler road, requires a little slack, only one point, out of the degree of 1, the point must be the starting point, a point, into the degree of 1 greater than the degree, this point must be the end point. The exit of the remaining points equals the degree of penetration
(Note that only a large 1, and such a point can only have 1, and the existence of a starting point must have an end, there must be a beginning point of existence)
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stack>6#include <vector>7#include <map>8#include <algorithm>9 #definemod=1e9+7;Ten using namespacestd; One AtypedefLong LongLL; - intdegree[10005],pre[10005],inch[10005], out[10005]; - Chars[10005]; the - - intFindintroot) { - returnRoot = = Pre[root]? Root:pre[root] =find (Pre[root]);} + - intMain () { + intT,n,i,j,flag,len,root; ACin>>T; at while(t--){ -Cin>>N; - - for(i=0; i<= -; i++) -pre[i]=i; -Memsetinch,0,sizeof(inch)); inMemset out,0,sizeof( out)); - to for(i=1; i<=n;i++){ +Cin>>s; -len=strlen (s); the * intu=s[0]-'a';intv=s[len-1]-'a'; $ out[u]++;inch[v]++;Panax Notoginseng -Pre[find (U)]=Find (v); theroot=Find (v); + } A the intans=0, inn=0, outt=0; + for(i=0; i<= -; i++){ - if(inch[i]| | out[i]) {//If there is a presence in or out of the degree, then continue to judge $ if(Find (Pre[i])!=root)//determine if they belong to the same unicom block $ans++; - if(inch[i]- out[i]==1)//if the number of points with a 1 greater than the degree of penetration is greater than 1, the condition is not met -inn++; the Else if( out[i]-inch[i]==1) -outt++;Wuyi Else if(ABS (inch[i]- out[i]) >1) the Break; - } Wu } - About if(i<= -|| Ans>0|| Inn>1|| Outt>1) printf ("The door cannot be opened.\n");//i<=30 indicates that no normal jump out of the loop, does not constitute Euler road $ Elseprintf"Ordering is possible.\n"); - } - return 0; -}View Code
UVa 10129 Play on Words "Euler Road and collection"