//雪花飄飄北風嘯嘯
//天地一片蒼茫
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << ": " << x << endl
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int MOD=998244353;
ll qexp(ll b,ll p,int m){
ll res=1;
while (p){
if (p&1) res=(res*b)%m;
b=(b*b)%m;
p>>=1;
}
return res;
}
ll inv(ll i){
return qexp(i,MOD-2,MOD);
}
ll fix(ll i){
i%=MOD;
if (i<0) i+=MOD;
return i;
}
ll fac[1000005];
ll ifac[1000005];
ll nCk(int i,int j){
if (i<j) return 0;
return fac[i]*ifac[j]%MOD*ifac[i-j]%MOD;
}
int n,m;
vector<int> al[1005];
vector<int> al2[1005];
bool path[1005];
bool vis[1005];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin.exceptions(ios::badbit | ios::failbit);
fac[0]=1;
rep(x,1,1000005) fac[x]=fac[x-1]*x%MOD;
ifac[1000004]=inv(fac[1000004]);
rep(x,1000005,1) ifac[x-1]=ifac[x]*x%MOD;
cin>>n>>m;
int a,b;
rep(x,0,m){
cin>>a>>b;
a--,b--;
al[a].pub(b);
al[b].pub(a);
}
if (n==1){
cout<<"YES"<<endl;
cout<<1<<endl;
cout<<1<<endl;
}
else if (n==2){
cout<<"YES"<<endl;
cout<<2<<endl;
cout<<2<<" "<<2<<endl;
}
else{
if (n==m+1){
rep(x,0,n) if (sz(al[x])!=1) path[x]=true;
rep(x,0,n) for (auto &it:al[x]){
if (path[x] && path[it]) al2[x].pub(it);
}
rep(x,0,n) swap(al[x],al2[x]);
rep(x,0,n) if (path[x] && sz(al[x])<=1){
memset(vis,false,sizeof(vis));
int curr=x;
vector<int> ans={x};
vis[x]=true;
bool can=true;
if (sz(al[x])) while (true){
int cnt=0;
for (auto &it:al[curr]) if (!vis[it]){
if (sz(al[it])>1) cnt++;
}
if (cnt>1){
can=false;
break;
}
if (cnt==0){
for (auto &it:al[curr]) if (!vis[it]){
vis[it]=true;
ans.pub(it);
ans.pub(curr);
}
ans.pob();
break;
}
else{
for (auto &it:al[curr]) if (!vis[it] && sz(al[it])==1){
vis[it]=true;
ans.pub(it);
ans.pub(curr);
}
for (auto &it:al[curr]) if (!vis[it]){
vis[it]=true;
ans.pub(it);
curr=it;
break;
}
}
}
if (can){
cout<<"YES"<<endl;
cout<<sz(ans)*2<<endl;
for (auto it:ans) cout<<it+1<<" ";
reverse(all(ans));
for (auto it:ans) cout<<it+1<<" "; cout<<endl;
return 0;
}
}
cout<<"NO"<<endl;
}
else{
cout<<"NO"<<endl;
}
}
}
Compilation message
newspapers.cpp: In function 'int main()':
newspapers.cpp:160:6: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
160 | for (auto it:ans) cout<<it+1<<" "; cout<<endl;
| ^~~
newspapers.cpp:160:41: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
160 | for (auto it:ans) cout<<it+1<<" "; cout<<endl;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
15948 KB |
Output is correct |
2 |
Correct |
17 ms |
15944 KB |
Output is correct |
3 |
Correct |
17 ms |
15964 KB |
Output is correct |
4 |
Correct |
17 ms |
16012 KB |
Output is correct |
5 |
Correct |
17 ms |
16020 KB |
Output is correct |
6 |
Correct |
16 ms |
15968 KB |
Output is correct |
7 |
Correct |
17 ms |
15948 KB |
Output is correct |
8 |
Correct |
17 ms |
15972 KB |
Output is correct |
9 |
Correct |
16 ms |
15948 KB |
Output is correct |
10 |
Correct |
17 ms |
16012 KB |
Output is correct |
11 |
Correct |
17 ms |
15940 KB |
Output is correct |
12 |
Correct |
17 ms |
16020 KB |
Output is correct |
13 |
Correct |
17 ms |
15916 KB |
Output is correct |
14 |
Correct |
16 ms |
15932 KB |
Output is correct |
15 |
Correct |
17 ms |
16020 KB |
Output is correct |
16 |
Correct |
16 ms |
16028 KB |
Output is correct |
17 |
Correct |
17 ms |
15948 KB |
Output is correct |
18 |
Correct |
17 ms |
16028 KB |
Output is correct |
19 |
Correct |
17 ms |
15948 KB |
Output is correct |
20 |
Correct |
17 ms |
15948 KB |
Output is correct |
21 |
Correct |
17 ms |
15948 KB |
Output is correct |
22 |
Correct |
17 ms |
15952 KB |
Output is correct |
23 |
Correct |
19 ms |
15948 KB |
Output is correct |
24 |
Correct |
16 ms |
15948 KB |
Output is correct |
25 |
Correct |
16 ms |
15948 KB |
Output is correct |
26 |
Correct |
16 ms |
16024 KB |
Output is correct |
27 |
Correct |
16 ms |
15932 KB |
Output is correct |
28 |
Correct |
17 ms |
16032 KB |
Output is correct |
29 |
Correct |
17 ms |
15904 KB |
Output is correct |
30 |
Correct |
17 ms |
15984 KB |
Output is correct |
31 |
Correct |
17 ms |
15980 KB |
Output is correct |
32 |
Correct |
20 ms |
15940 KB |
Output is correct |
33 |
Correct |
16 ms |
15948 KB |
Output is correct |
34 |
Correct |
17 ms |
15940 KB |
Output is correct |
35 |
Correct |
17 ms |
16020 KB |
Output is correct |
36 |
Correct |
17 ms |
16020 KB |
Output is correct |
37 |
Correct |
17 ms |
15940 KB |
Output is correct |
38 |
Correct |
16 ms |
15980 KB |
Output is correct |
39 |
Correct |
16 ms |
15972 KB |
Output is correct |
40 |
Correct |
16 ms |
15948 KB |
Output is correct |
41 |
Correct |
16 ms |
15916 KB |
Output is correct |
42 |
Correct |
17 ms |
16024 KB |
Output is correct |
43 |
Correct |
16 ms |
15972 KB |
Output is correct |
44 |
Correct |
17 ms |
15948 KB |
Output is correct |
45 |
Correct |
20 ms |
15916 KB |
Output is correct |
46 |
Correct |
17 ms |
15932 KB |
Output is correct |
47 |
Correct |
17 ms |
15948 KB |
Output is correct |
48 |
Correct |
17 ms |
15948 KB |
Output is correct |
49 |
Correct |
17 ms |
15996 KB |
Output is correct |
50 |
Correct |
17 ms |
15948 KB |
Output is correct |
51 |
Correct |
18 ms |
15948 KB |
Output is correct |
52 |
Correct |
17 ms |
16020 KB |
Output is correct |
53 |
Correct |
19 ms |
16048 KB |
Output is correct |
54 |
Correct |
18 ms |
15932 KB |
Output is correct |
55 |
Correct |
17 ms |
16008 KB |
Output is correct |
56 |
Correct |
18 ms |
15948 KB |
Output is correct |
57 |
Correct |
17 ms |
16024 KB |
Output is correct |
58 |
Correct |
16 ms |
15916 KB |
Output is correct |
59 |
Correct |
17 ms |
15936 KB |
Output is correct |
60 |
Correct |
17 ms |
15948 KB |
Output is correct |
61 |
Correct |
19 ms |
15948 KB |
Output is correct |
62 |
Correct |
16 ms |
15936 KB |
Output is correct |
63 |
Correct |
17 ms |
15980 KB |
Output is correct |
64 |
Correct |
17 ms |
15948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
15908 KB |
Output is correct |
2 |
Correct |
17 ms |
16016 KB |
Output is correct |
3 |
Correct |
17 ms |
15948 KB |
Output is correct |
4 |
Correct |
16 ms |
15904 KB |
Output is correct |
5 |
Correct |
17 ms |
15960 KB |
Output is correct |
6 |
Correct |
17 ms |
15948 KB |
Output is correct |
7 |
Correct |
18 ms |
15948 KB |
Output is correct |
8 |
Correct |
16 ms |
16016 KB |
Output is correct |
9 |
Correct |
16 ms |
16024 KB |
Output is correct |
10 |
Correct |
17 ms |
15904 KB |
Output is correct |
11 |
Correct |
21 ms |
16032 KB |
Output is correct |
12 |
Correct |
17 ms |
16000 KB |
Output is correct |
13 |
Correct |
17 ms |
16088 KB |
Output is correct |
14 |
Correct |
18 ms |
16068 KB |
Output is correct |
15 |
Correct |
17 ms |
16024 KB |
Output is correct |
16 |
Correct |
17 ms |
16076 KB |
Output is correct |
17 |
Correct |
17 ms |
16060 KB |
Output is correct |
18 |
Correct |
18 ms |
16060 KB |
Output is correct |
19 |
Correct |
16 ms |
16076 KB |
Output is correct |
20 |
Correct |
17 ms |
16076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
15948 KB |
Output is correct |
2 |
Correct |
17 ms |
15944 KB |
Output is correct |
3 |
Correct |
17 ms |
15964 KB |
Output is correct |
4 |
Correct |
17 ms |
16012 KB |
Output is correct |
5 |
Correct |
17 ms |
16020 KB |
Output is correct |
6 |
Correct |
16 ms |
15968 KB |
Output is correct |
7 |
Correct |
17 ms |
15948 KB |
Output is correct |
8 |
Correct |
17 ms |
15972 KB |
Output is correct |
9 |
Correct |
16 ms |
15948 KB |
Output is correct |
10 |
Correct |
17 ms |
16012 KB |
Output is correct |
11 |
Correct |
17 ms |
15940 KB |
Output is correct |
12 |
Correct |
17 ms |
16020 KB |
Output is correct |
13 |
Correct |
17 ms |
15916 KB |
Output is correct |
14 |
Correct |
16 ms |
15932 KB |
Output is correct |
15 |
Correct |
17 ms |
16020 KB |
Output is correct |
16 |
Correct |
16 ms |
16028 KB |
Output is correct |
17 |
Correct |
17 ms |
15948 KB |
Output is correct |
18 |
Correct |
17 ms |
16028 KB |
Output is correct |
19 |
Correct |
17 ms |
15948 KB |
Output is correct |
20 |
Correct |
17 ms |
15948 KB |
Output is correct |
21 |
Correct |
17 ms |
15948 KB |
Output is correct |
22 |
Correct |
17 ms |
15952 KB |
Output is correct |
23 |
Correct |
19 ms |
15948 KB |
Output is correct |
24 |
Correct |
16 ms |
15948 KB |
Output is correct |
25 |
Correct |
16 ms |
15948 KB |
Output is correct |
26 |
Correct |
16 ms |
16024 KB |
Output is correct |
27 |
Correct |
16 ms |
15932 KB |
Output is correct |
28 |
Correct |
17 ms |
16032 KB |
Output is correct |
29 |
Correct |
17 ms |
15904 KB |
Output is correct |
30 |
Correct |
17 ms |
15984 KB |
Output is correct |
31 |
Correct |
17 ms |
15980 KB |
Output is correct |
32 |
Correct |
20 ms |
15940 KB |
Output is correct |
33 |
Correct |
16 ms |
15948 KB |
Output is correct |
34 |
Correct |
17 ms |
15940 KB |
Output is correct |
35 |
Correct |
17 ms |
16020 KB |
Output is correct |
36 |
Correct |
17 ms |
16020 KB |
Output is correct |
37 |
Correct |
17 ms |
15940 KB |
Output is correct |
38 |
Correct |
16 ms |
15980 KB |
Output is correct |
39 |
Correct |
16 ms |
15972 KB |
Output is correct |
40 |
Correct |
16 ms |
15948 KB |
Output is correct |
41 |
Correct |
16 ms |
15916 KB |
Output is correct |
42 |
Correct |
17 ms |
16024 KB |
Output is correct |
43 |
Correct |
16 ms |
15972 KB |
Output is correct |
44 |
Correct |
17 ms |
15948 KB |
Output is correct |
45 |
Correct |
20 ms |
15916 KB |
Output is correct |
46 |
Correct |
17 ms |
15932 KB |
Output is correct |
47 |
Correct |
17 ms |
15948 KB |
Output is correct |
48 |
Correct |
17 ms |
15948 KB |
Output is correct |
49 |
Correct |
17 ms |
15996 KB |
Output is correct |
50 |
Correct |
17 ms |
15948 KB |
Output is correct |
51 |
Correct |
18 ms |
15948 KB |
Output is correct |
52 |
Correct |
17 ms |
16020 KB |
Output is correct |
53 |
Correct |
19 ms |
16048 KB |
Output is correct |
54 |
Correct |
18 ms |
15932 KB |
Output is correct |
55 |
Correct |
17 ms |
16008 KB |
Output is correct |
56 |
Correct |
18 ms |
15948 KB |
Output is correct |
57 |
Correct |
17 ms |
16024 KB |
Output is correct |
58 |
Correct |
16 ms |
15916 KB |
Output is correct |
59 |
Correct |
17 ms |
15936 KB |
Output is correct |
60 |
Correct |
17 ms |
15948 KB |
Output is correct |
61 |
Correct |
19 ms |
15948 KB |
Output is correct |
62 |
Correct |
16 ms |
15936 KB |
Output is correct |
63 |
Correct |
17 ms |
15980 KB |
Output is correct |
64 |
Correct |
17 ms |
15948 KB |
Output is correct |
65 |
Correct |
17 ms |
15964 KB |
Output is correct |
66 |
Correct |
18 ms |
15948 KB |
Output is correct |
67 |
Correct |
16 ms |
15896 KB |
Output is correct |
68 |
Correct |
19 ms |
15960 KB |
Output is correct |
69 |
Correct |
16 ms |
15912 KB |
Output is correct |
70 |
Correct |
17 ms |
15948 KB |
Output is correct |
71 |
Correct |
16 ms |
16024 KB |
Output is correct |
72 |
Correct |
16 ms |
15948 KB |
Output is correct |
73 |
Correct |
17 ms |
15968 KB |
Output is correct |
74 |
Correct |
17 ms |
15948 KB |
Output is correct |
75 |
Correct |
17 ms |
15988 KB |
Output is correct |
76 |
Correct |
17 ms |
16004 KB |
Output is correct |
77 |
Correct |
17 ms |
15948 KB |
Output is correct |
78 |
Correct |
16 ms |
15948 KB |
Output is correct |
79 |
Correct |
17 ms |
15948 KB |
Output is correct |
80 |
Correct |
16 ms |
16020 KB |
Output is correct |
81 |
Correct |
17 ms |
16028 KB |
Output is correct |
82 |
Correct |
17 ms |
16004 KB |
Output is correct |
83 |
Correct |
17 ms |
16056 KB |
Output is correct |
84 |
Correct |
18 ms |
16032 KB |
Output is correct |
85 |
Correct |
17 ms |
15956 KB |
Output is correct |
86 |
Correct |
17 ms |
15952 KB |
Output is correct |
87 |
Correct |
17 ms |
16076 KB |
Output is correct |
88 |
Correct |
17 ms |
16028 KB |
Output is correct |
89 |
Correct |
19 ms |
16076 KB |
Output is correct |
90 |
Correct |
17 ms |
16076 KB |
Output is correct |
91 |
Correct |
17 ms |
16028 KB |
Output is correct |
92 |
Correct |
17 ms |
16076 KB |
Output is correct |
93 |
Correct |
16 ms |
16076 KB |
Output is correct |
94 |
Correct |
17 ms |
16076 KB |
Output is correct |
95 |
Correct |
18 ms |
16076 KB |
Output is correct |
96 |
Correct |
17 ms |
16028 KB |
Output is correct |
97 |
Correct |
17 ms |
16076 KB |
Output is correct |
98 |
Correct |
17 ms |
16032 KB |
Output is correct |
99 |
Correct |
16 ms |
16096 KB |
Output is correct |
100 |
Correct |
17 ms |
16056 KB |
Output is correct |
101 |
Correct |
16 ms |
16024 KB |
Output is correct |
102 |
Correct |
17 ms |
16076 KB |
Output is correct |
103 |
Correct |
18 ms |
16056 KB |
Output is correct |
104 |
Correct |
17 ms |
16076 KB |
Output is correct |
105 |
Correct |
18 ms |
16016 KB |
Output is correct |
106 |
Correct |
17 ms |
16076 KB |
Output is correct |
107 |
Correct |
17 ms |
16076 KB |
Output is correct |
108 |
Correct |
17 ms |
16076 KB |
Output is correct |
109 |
Correct |
17 ms |
16096 KB |
Output is correct |
110 |
Correct |
17 ms |
15992 KB |
Output is correct |
111 |
Correct |
18 ms |
16056 KB |
Output is correct |
112 |
Correct |
17 ms |
16044 KB |
Output is correct |
113 |
Correct |
18 ms |
16056 KB |
Output is correct |
114 |
Correct |
20 ms |
15968 KB |
Output is correct |
115 |
Correct |
18 ms |
16052 KB |
Output is correct |
116 |
Correct |
18 ms |
16012 KB |
Output is correct |
117 |
Correct |
19 ms |
16076 KB |
Output is correct |
118 |
Correct |
18 ms |
16076 KB |
Output is correct |
119 |
Correct |
19 ms |
16028 KB |
Output is correct |
120 |
Correct |
19 ms |
16024 KB |
Output is correct |
121 |
Correct |
18 ms |
16048 KB |
Output is correct |
122 |
Correct |
18 ms |
16076 KB |
Output is correct |
123 |
Correct |
19 ms |
16076 KB |
Output is correct |
124 |
Correct |
19 ms |
16024 KB |
Output is correct |
125 |
Correct |
19 ms |
16004 KB |
Output is correct |
126 |
Correct |
19 ms |
16060 KB |
Output is correct |
127 |
Correct |
21 ms |
15972 KB |
Output is correct |
128 |
Correct |
19 ms |
16076 KB |
Output is correct |
129 |
Correct |
17 ms |
16076 KB |
Output is correct |
130 |
Correct |
16 ms |
16060 KB |
Output is correct |
131 |
Correct |
18 ms |
16000 KB |
Output is correct |
132 |
Correct |
17 ms |
16024 KB |
Output is correct |
133 |
Correct |
17 ms |
16076 KB |
Output is correct |
134 |
Correct |
34 ms |
17596 KB |
Output is correct |
135 |
Correct |
31 ms |
17552 KB |
Output is correct |
136 |
Correct |
51 ms |
21016 KB |
Output is correct |
137 |
Correct |
43 ms |
18944 KB |
Output is correct |
138 |
Correct |
62 ms |
20296 KB |
Output is correct |
139 |
Correct |
99 ms |
23464 KB |
Output is correct |
140 |
Correct |
31 ms |
17168 KB |
Output is correct |
141 |
Correct |
22 ms |
16392 KB |
Output is correct |
142 |
Correct |
87 ms |
23200 KB |
Output is correct |
143 |
Correct |
99 ms |
23876 KB |
Output is correct |
144 |
Correct |
20 ms |
16080 KB |
Output is correct |
145 |
Correct |
18 ms |
16060 KB |
Output is correct |