-
Notifications
You must be signed in to change notification settings - Fork 0
/
1341.cpp
77 lines (76 loc) · 1.27 KB
/
1341.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<vector>
#define IL inline
#define re register
#define LL long long
#define ULL unsigned long long
#define re register
using namespace std;
const int le='A',ri='z';
int cnt,kind,n,s=100;
bool ver[1000][1000];
int degree[1000];
void insert(int u,int v)
{
ver[u][v]=ver[v][u]=1;
degree[u]++;
degree[v]++;
}
bool book[1000][1000];
bool succ;
vector<int>vec;
void dfs(int depth,int now)
{
if(succ) return;
if(depth==n){
succ=1;
for(int i=0;i<vec.size();i++) cout<<(char)(vec[i]+le);
return;
}
for(int i=0;i<58;i++)
{
if(ver[now][i])
if(!book[now][i]&&!book[i][now])
{
book[now][i]=1;
book[i][now]=1;
vec.push_back(i);
dfs(depth+1,i);
book[now][i]=0;
book[i][now]=0;
vec.pop_back();
}
}
}
int main()
{
// freopen("P1341_2.in","r",stdin);
// freopen(".out","w",stdout);
cin>>n;
int start=0;
string t;
for(int i=0;i<n;i++)
{
cin>>t;
insert(t[1]-'A',t[0]-'A');
s=min(s,t[0]-'A');
s=min(s,t[1]-'A');
}
int sum=0;
for(int i=0;i<58;i++) if(degree[i]&1) {
if(!sum) start=i;
sum++;
}
if(sum!=0&&sum!=2) return cout<<"No Solution"&&0;
if(!sum) start=s;
vec.push_back(start);
dfs(0,start);
return 0;
}