Topic links
Here you are. n a substring of length 3, these substrings are derived from a string of length n+2, the original string, if given illegal, output-1.
A problem of the Euler path, the first two characters of the substring and the latter two character as a point, such as ACB, is AC->CB. Then build the diagram.
1#include <iostream>2#include <vector>3#include <cstdio>4#include <cstring>5#include <algorithm>6#include <cmath>7#include <map>8#include <Set>9#include <stack>Ten#include <string> One#include <queue> A using namespacestd; - #definePB (x) push_back (x) - #definell Long Long the #defineMK (x, y) make_pair (x, y) - #defineLson L, M, rt<<1 - #defineMem (a) memset (a, 0, sizeof (a)) - #defineRson m+1, R, rt<<1|1 + #defineMem1 (a) memset (a,-1, sizeof (a)) - #defineMEM2 (a) memset (a, 0x3f, sizeof (a)) + #defineRep (i, N, a) for (int i = A; i<n; i++) A #defineFi first at #defineSe Second -typedef pair<int,int>PLL; - Const DoublePI = ACOs (-1.0); - Const DoubleEPS = 1e-8; - Const intMoD = 1e9+7; - Const intINF =1061109567; in Const intdir[][2] = { {-1,0}, {1,0}, {0, -1}, {0,1} }; -Map <string,int>Ma; to stringa[400005]; + intCNT, inde[400005], outde[400005], vis[400005*2], num, ans[2*400005], ecnt[66000]; -Vector <int> v[66000]; the voidDfsintu) { * while(ecnt[u]<v[u].size ()) { $DFS (v[u][ecnt[u]++]);Panax Notoginseng } -ans[num++] = u% the; the } + intMain () A { theIos::sync_with_stdio (0); + strings, tmp; - intN, Pos1, Pos2; $Cin>>N; $ intCNT =1, start; - for(inti =0; i<n; i++) { -Cin>>s; the intU = the*s[0]+s[1]; - intto = the*s[1]+s[2];Wuyi V[U].PB (to); theinde[to]++; -outde[u]++; WuStart =u; - } AboutPOS1 =-1, Pos2 =-1; $ intFlag =0; - for(inti =1; i<66000; i++) { - if(outde[i]!=Inde[i]) { - if(outde[i]==inde[i]+1) { A if(pos1==-1) { +POS1 =i; the}Else { -Flag =1; $ } the}Else { the if(pos2==-1) thePos2=i; the Else -Flag =1; in } the } the } About if(Flag| | (pos1==-1&&pos2!=-1|| pos2==-1&&pos1!=-1)) { thecout<<"NO"<<Endl; the return 0; the } +num =0; - if(POS1 = =-1) thePOS1 =start;Bayi DFS (POS1); the if(num! = n+1) { thePuts"NO"); - return 0; - } thes ="", TMP =""; theTMP = (Char) (pos1/ the); the for(inti = num-1; i>=0; i--) { theTMP + =Char(Ans[i]); - } thecout<<"YES"<<Endl; thecout<<tmp; the return 0;94}
Codeforces 508D. Tanya and Password Euler pathway