This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//雪花飄飄北風嘯嘯
//天地一片蒼茫
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |