# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1114587 | 2024-11-19T08:15:18 Z | vjudge1 | Newspapers (CEOI21_newspapers) | C++17 | 2 ms | 504 KB |
#include<bits/stdc++.h> using namespace std; #define int long long #define pb push_back using pii=pair<int,int>; int parent[5000]; int find(int i){ if(parent[i]==i)return i; return parent[i]=find(parent[i]); } int unite(int i,int j){ i=find(i);j=find(j); if(i==j)return 1; parent[i]=j; return 0; } signed main(){ int n,m; cin>>n>>m; if(n==1){ cout<<"YES\n1\n1"; return 0; } for(int i=1;i<=n;i++)parent[i]=i; vector<int>v[n+1]; for(int i=0;i<m;i++){ int x,y; cin>>x>>y; v[x].pb(y); v[y].pb(x); if(unite(x,y)){ cout<<"NO\n"; return 0; } } int guy=0; for(int i=1;i<=n;i++){ if(v[i].size()>2){ if(guy){ cout<<"NO\n"; return 0; } guy=i; } } if(!guy){ for(int i=1;i<=n;i++){ if(v[i].size()==1){ guy=v[i][0]; break; } } } cout<<"YES\n"; vector<int>chain; chain.pb(guy); while(1){ int now=chain.back(); for(int j:v[now]){ if((guy!=now&&chain[chain.size()-2]!=j)||(guy==now&&v[j].size()>1)){ chain.pb(j); break; } } if(chain.back()==now){ break; } } vector<int>ans; for(int i=0;i<chain.size();i++){ ans.pb(chain[i]); } for(int i=chain.size()-1;0<=i;i--){ ans.pb(chain[i]); } cout<<ans.size()<<'\n'; for(int i:ans)cout<<i<<' '; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Partially correct | 1 ms | 336 KB | Provide a successful but not optimal strategy. |
4 | Partially correct | 1 ms | 336 KB | Provide a successful but not optimal strategy. |
5 | Correct | 1 ms | 336 KB | Output is correct |
6 | Incorrect | 1 ms | 336 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 336 KB | Output is correct |
4 | Partially correct | 1 ms | 336 KB | Provide a successful but not optimal strategy. |
5 | Partially correct | 1 ms | 336 KB | Provide a successful but not optimal strategy. |
6 | Partially correct | 1 ms | 336 KB | Provide a successful but not optimal strategy. |
7 | Partially correct | 1 ms | 336 KB | Provide a successful but not optimal strategy. |
8 | Partially correct | 1 ms | 336 KB | Provide a successful but not optimal strategy. |
9 | Partially correct | 1 ms | 336 KB | Provide a successful but not optimal strategy. |
10 | Partially correct | 1 ms | 336 KB | Provide a successful but not optimal strategy. |
11 | Partially correct | 1 ms | 336 KB | Provide a successful but not optimal strategy. |
12 | Partially correct | 1 ms | 336 KB | Provide a successful but not optimal strategy. |
13 | Partially correct | 1 ms | 336 KB | Provide a successful but not optimal strategy. |
14 | Partially correct | 1 ms | 336 KB | Provide a successful but not optimal strategy. |
15 | Partially correct | 2 ms | 336 KB | Provide a successful but not optimal strategy. |
16 | Partially correct | 1 ms | 336 KB | Provide a successful but not optimal strategy. |
17 | Partially correct | 1 ms | 336 KB | Provide a successful but not optimal strategy. |
18 | Partially correct | 1 ms | 504 KB | Provide a successful but not optimal strategy. |
19 | Partially correct | 1 ms | 336 KB | Provide a successful but not optimal strategy. |
20 | Partially correct | 1 ms | 336 KB | Provide a successful but not optimal strategy. |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Partially correct | 1 ms | 336 KB | Provide a successful but not optimal strategy. |
4 | Partially correct | 1 ms | 336 KB | Provide a successful but not optimal strategy. |
5 | Correct | 1 ms | 336 KB | Output is correct |
6 | Incorrect | 1 ms | 336 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |