题本身不是很难,欧拉路径是想到了,但是第一次写总是不太顺利,写完之后还tle了一次,主要是用vector做邻接表无法高效删除边,之后改成list,,AC速度还比其他邻接矩阵快很多
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cctype>
#include<cstdlib>
#include<list>
#include<stack>
#define FOR(s,n) for(int i=(s);i<(n);i++)
#define REP(n) for(int R=0;R<(n);R++)
typedef long long i64;
#define MX 62*62+10
using namespace std;
list<int> G[MX];
int ind[MX],outd[MX];
int N;
char scan[4];
int dig[3];
stack<int> store;
int cont=0;
void dfs(int s){
while(!G[s].empty()){
int v=G[s].front();
G[s].pop_front();
dfs(v);
}
cont++;
store.push(s);
}
char fuc(int a){
if(a<10) return (char)('0'+a);
else if(a<36) return (char)('A'+a-10);
else return (char)('a'+a-36);
}
int main(){
cin>>N;
REP(N){
scanf("%s",scan);
FOR(0,3){
if(isupper(scan[i]))
dig[i]=scan[i]-'A'+10;
else if(islower(scan[i]))
dig[i]=scan[i]-'a'+36;
else
dig[i]=scan[i]-'0';
}
int lab1=62*dig[0]+dig[1];
int lab2=62*dig[1]+dig[2];
G[lab1].push_back(lab2);
outd[lab1]++,ind[lab2]++;
}
bool ok=1;
int inn=-1,outn=-1;///起点和终点
bool setedi=0,setedo=0;
FOR(0,62*62){
if(outd[i]-ind[i]==1){
if(!setedo)
outn=i,setedo=1;
else
{ok=0;break;}
}
else if(outd[i]-ind[i]==-1){
if(!setedi)
setedi=1,inn=i;
else
{ok=0;break;}
}
else if(outd[i]-ind[i]!=0){
ok=0;
break;
}
else if(outd[i]==ind[i]&&outd[i]!=0&&inn==-1&&outn==-1)
inn=outn=i;
}
if(ok&&outn!=-1&&inn!=-1){
string ans;
dfs(outn);
if(cont==N+1){
cout<<"YES"<<endl;
int first=store.top();
store.pop();
ans.push_back(fuc(first/62));
ans.push_back(fuc(first%62));
while(!store.empty())ans.push_back(fuc(store.top()%62)),store.pop();
cout<<ans<<endl;
}
else
cout<<"NO"<<endl;
}
else
cout<<"NO"<<endl;
return 0;
}