#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,i,j,ii,jj,zx,xc,p[5009],pi,kl[1003][1003],DP[1009],l[5009],li,bo[5009],P[5009],PI;
int CH[1009][1009];
vector <int> v[1009];
void print(){
pi=PI;
for(i=1; i<=PI; i++){
p[i]=P[i];
}
cout<<"YES\n";
cout<<pi<<"\n";
for(i=1; i<=pi; i++){
cout<<p[i]<<" ";
}
/*
cout<<"\n";
for(i=1; i<=a; i++) CH[0][i]=1;
for(j=1; j<=pi; j++){
for(i=1; i<=a; i++){
CH[j][i]=0;
for(vector <int>::iterator it=v[i].begin(); it!=v[i].end(); it++){
if(p[j]!=(*it)&&CH[j-1][(*it)]==1){
CH[j][i]=1;break;
}
}
}
}
e=0;
for(i=1; i<=a; i++){
if(CH[pi][i]==1) e++;
}
cout<<"WRONG: "<<e;
*/
exit(0);
}
void dfs(int q, int w, int rr){
e=max(e,rr);
for(vector <int>::iterator it=v[q].begin(); it!=v[q].end(); it++){
if((*it)==w) continue;
dfs((*it),q,rr+1);
}
}
void dfs2(int q, int w){
int I=i;
li++;l[li]=q;bo[q]=1;
if(DP[q]-kl[q][w]==0){
pi=0;
for(j=1; j<=li; j++){
pi++;p[pi]=l[j];
for(vector <int>::iterator it=v[l[j]].begin(); it!=v[l[j]].end(); it++){
if(bo[(*it)]==1) continue;
if(v[(*it)].size()!=1){
pi++;p[pi]=(*it);
pi++;p[pi]=l[j];
}
}
}
for(i=pi; i>=1; i--){
pi++;p[pi]=p[i];
}
if(PI>pi){
PI=pi;
for(i=1; i<=pi; i++) P[i]=p[i];
}
i=I;
//print();
}
for(vector <int>::iterator it=v[q].begin(); it!=v[q].end(); it++){
if((*it)==w) continue;
if(DP[q]-kl[q][w]-kl[q][(*it)]>0) continue;
dfs2((*it),q);
}
li--;bo[q]=0;
}
int main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>a>>b;PI=10*a+10;
for(i=1; i<=b; i++){
cin>>c>>d;
v[c].push_back(d);
v[d].push_back(c);
}
if(a==1){
PI=1;P[1]=1;
print();
}
if(a==2){
PI=2;P[1]=1;P[2]=1;
print();
}
if(b!=a-1){
cout<<"NO";
return 0;
}
for(i=1; i<=a; i++){
for(vector <int>::iterator it=v[i].begin(); it!=v[i].end(); it++){
e=0;
dfs((*it),i,1);
if(e>2){
kl[i][(*it)]=1;DP[i]++;
}
}
}
for(i=1; i<=a; i++){
dfs2(i,0);
}
if(PI!=10*a+10){
print();
}
cout<<"NO";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
352 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
0 ms |
332 KB |
Output is correct |
34 |
Correct |
0 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
0 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
0 ms |
332 KB |
Output is correct |
44 |
Correct |
1 ms |
332 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
0 ms |
332 KB |
Output is correct |
49 |
Correct |
0 ms |
332 KB |
Output is correct |
50 |
Correct |
1 ms |
336 KB |
Output is correct |
51 |
Correct |
1 ms |
336 KB |
Output is correct |
52 |
Correct |
1 ms |
332 KB |
Output is correct |
53 |
Correct |
0 ms |
332 KB |
Output is correct |
54 |
Correct |
0 ms |
332 KB |
Output is correct |
55 |
Correct |
0 ms |
344 KB |
Output is correct |
56 |
Correct |
0 ms |
332 KB |
Output is correct |
57 |
Correct |
0 ms |
332 KB |
Output is correct |
58 |
Correct |
0 ms |
332 KB |
Output is correct |
59 |
Correct |
0 ms |
332 KB |
Output is correct |
60 |
Correct |
0 ms |
332 KB |
Output is correct |
61 |
Correct |
0 ms |
332 KB |
Output is correct |
62 |
Correct |
0 ms |
332 KB |
Output is correct |
63 |
Correct |
0 ms |
344 KB |
Output is correct |
64 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
11 ms |
4184 KB |
Output is correct |
12 |
Correct |
4 ms |
2380 KB |
Output is correct |
13 |
Correct |
4 ms |
2764 KB |
Output is correct |
14 |
Correct |
5 ms |
2908 KB |
Output is correct |
15 |
Correct |
6 ms |
3020 KB |
Output is correct |
16 |
Correct |
14 ms |
4420 KB |
Output is correct |
17 |
Correct |
12 ms |
4348 KB |
Output is correct |
18 |
Correct |
11 ms |
4428 KB |
Output is correct |
19 |
Correct |
12 ms |
4440 KB |
Output is correct |
20 |
Correct |
11 ms |
4428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
352 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
0 ms |
332 KB |
Output is correct |
34 |
Correct |
0 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
0 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
0 ms |
332 KB |
Output is correct |
44 |
Correct |
1 ms |
332 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
0 ms |
332 KB |
Output is correct |
49 |
Correct |
0 ms |
332 KB |
Output is correct |
50 |
Correct |
1 ms |
336 KB |
Output is correct |
51 |
Correct |
1 ms |
336 KB |
Output is correct |
52 |
Correct |
1 ms |
332 KB |
Output is correct |
53 |
Correct |
0 ms |
332 KB |
Output is correct |
54 |
Correct |
0 ms |
332 KB |
Output is correct |
55 |
Correct |
0 ms |
344 KB |
Output is correct |
56 |
Correct |
0 ms |
332 KB |
Output is correct |
57 |
Correct |
0 ms |
332 KB |
Output is correct |
58 |
Correct |
0 ms |
332 KB |
Output is correct |
59 |
Correct |
0 ms |
332 KB |
Output is correct |
60 |
Correct |
0 ms |
332 KB |
Output is correct |
61 |
Correct |
0 ms |
332 KB |
Output is correct |
62 |
Correct |
0 ms |
332 KB |
Output is correct |
63 |
Correct |
0 ms |
344 KB |
Output is correct |
64 |
Correct |
0 ms |
340 KB |
Output is correct |
65 |
Correct |
0 ms |
332 KB |
Output is correct |
66 |
Correct |
0 ms |
332 KB |
Output is correct |
67 |
Correct |
0 ms |
332 KB |
Output is correct |
68 |
Correct |
0 ms |
332 KB |
Output is correct |
69 |
Correct |
0 ms |
332 KB |
Output is correct |
70 |
Correct |
0 ms |
332 KB |
Output is correct |
71 |
Correct |
0 ms |
332 KB |
Output is correct |
72 |
Correct |
1 ms |
332 KB |
Output is correct |
73 |
Correct |
0 ms |
332 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
0 ms |
332 KB |
Output is correct |
76 |
Correct |
1 ms |
332 KB |
Output is correct |
77 |
Correct |
1 ms |
332 KB |
Output is correct |
78 |
Correct |
1 ms |
344 KB |
Output is correct |
79 |
Correct |
11 ms |
3424 KB |
Output is correct |
80 |
Correct |
10 ms |
3404 KB |
Output is correct |
81 |
Correct |
10 ms |
3532 KB |
Output is correct |
82 |
Correct |
12 ms |
3732 KB |
Output is correct |
83 |
Correct |
11 ms |
3660 KB |
Output is correct |
84 |
Correct |
9 ms |
3552 KB |
Output is correct |
85 |
Correct |
10 ms |
3484 KB |
Output is correct |
86 |
Correct |
10 ms |
3532 KB |
Output is correct |
87 |
Correct |
10 ms |
3660 KB |
Output is correct |
88 |
Correct |
9 ms |
3312 KB |
Output is correct |
89 |
Correct |
19 ms |
3872 KB |
Output is correct |
90 |
Correct |
15 ms |
3428 KB |
Output is correct |
91 |
Correct |
16 ms |
3320 KB |
Output is correct |
92 |
Correct |
12 ms |
3104 KB |
Output is correct |
93 |
Correct |
19 ms |
3792 KB |
Output is correct |
94 |
Correct |
13 ms |
3268 KB |
Output is correct |
95 |
Correct |
19 ms |
3908 KB |
Output is correct |
96 |
Correct |
22 ms |
3800 KB |
Output is correct |
97 |
Correct |
12 ms |
3020 KB |
Output is correct |
98 |
Correct |
19 ms |
3780 KB |
Output is correct |
99 |
Correct |
14 ms |
3360 KB |
Output is correct |
100 |
Correct |
15 ms |
3532 KB |
Output is correct |
101 |
Correct |
13 ms |
3404 KB |
Output is correct |
102 |
Correct |
14 ms |
3404 KB |
Output is correct |
103 |
Correct |
20 ms |
3484 KB |
Output is correct |
104 |
Correct |
15 ms |
3060 KB |
Output is correct |
105 |
Correct |
13 ms |
3300 KB |
Output is correct |
106 |
Correct |
15 ms |
3548 KB |
Output is correct |
107 |
Correct |
12 ms |
3304 KB |
Output is correct |
108 |
Correct |
18 ms |
3788 KB |
Output is correct |
109 |
Correct |
15 ms |
3532 KB |
Output is correct |
110 |
Correct |
15 ms |
3480 KB |
Output is correct |
111 |
Correct |
13 ms |
3244 KB |
Output is correct |
112 |
Correct |
14 ms |
3320 KB |
Output is correct |
113 |
Correct |
20 ms |
3800 KB |
Output is correct |
114 |
Correct |
16 ms |
3588 KB |
Output is correct |
115 |
Correct |
13 ms |
3380 KB |
Output is correct |
116 |
Correct |
16 ms |
3532 KB |
Output is correct |
117 |
Correct |
19 ms |
3780 KB |
Output is correct |
118 |
Correct |
17 ms |
3588 KB |
Output is correct |
119 |
Correct |
19 ms |
3384 KB |
Output is correct |
120 |
Correct |
17 ms |
3596 KB |
Output is correct |
121 |
Correct |
17 ms |
3608 KB |
Output is correct |
122 |
Correct |
15 ms |
3296 KB |
Output is correct |
123 |
Correct |
12 ms |
3276 KB |
Output is correct |
124 |
Correct |
19 ms |
3792 KB |
Output is correct |
125 |
Correct |
12 ms |
3040 KB |
Output is correct |
126 |
Correct |
13 ms |
3148 KB |
Output is correct |
127 |
Correct |
13 ms |
3148 KB |
Output is correct |
128 |
Correct |
18 ms |
3764 KB |
Output is correct |
129 |
Correct |
14 ms |
4056 KB |
Output is correct |
130 |
Correct |
14 ms |
4036 KB |
Output is correct |
131 |
Correct |
14 ms |
3948 KB |
Output is correct |
132 |
Correct |
14 ms |
4044 KB |
Output is correct |
133 |
Correct |
13 ms |
4080 KB |
Output is correct |
134 |
Correct |
14 ms |
1932 KB |
Output is correct |
135 |
Correct |
12 ms |
1996 KB |
Output is correct |
136 |
Correct |
30 ms |
5304 KB |
Output is correct |
137 |
Correct |
20 ms |
3224 KB |
Output is correct |
138 |
Correct |
33 ms |
4660 KB |
Output is correct |
139 |
Correct |
66 ms |
6848 KB |
Output is correct |
140 |
Correct |
9 ms |
1348 KB |
Output is correct |
141 |
Correct |
3 ms |
612 KB |
Output is correct |
142 |
Correct |
56 ms |
6820 KB |
Output is correct |
143 |
Correct |
68 ms |
6784 KB |
Output is correct |
144 |
Correct |
11 ms |
4428 KB |
Output is correct |
145 |
Correct |
11 ms |
4556 KB |
Output is correct |