Submission #1108580

#TimeUsernameProblemLanguageResultExecution timeMemory
1108580razivoNewspapers (CEOI21_newspapers)C++14
0 / 100
1 ms336 KiB
#include <iostream> #include <vector> using namespace std; vector<int> res; vector<bool> b; bool dfs(int c, int p,vector<vector<int>> &g) { res.push_back(c); int r = true; int count = 0; bool h = false; for(auto i:g[c]) { if(g[i].size()==1) h=true; } b.push_back(h); for(auto i:g[c]) { if(i==p) continue; if(g[i].size()==1) continue; r&=dfs(i,c,g); count++; } if(count>1) return false; return r; } int main() { int n,m; cin>>n>>m; if(m!=n-1) { cout<<"NO"<<endl; exit(0); } vector<vector<int>> g(n); for (int i = 0; i < m; ++i) { int x,y; cin>>x>>y; x--; y--; g[x].push_back(y); g[y].push_back(x); } if(n==2) { cout<<"YES"<<endl; cout<<"1 1"<<endl; exit(0); } int cur = 0; while(true) { if(cur==n) break; if(g[cur].size()==1) {cur++; continue;} int count = 0; for(int i : g[cur]) if(g[i].size()!=1) count++; if(count==1) break; cur++; } if(cur==n) { int cur = 0; while(true) { if(g[cur].size()!=1) break; cur++; } cout<<"YES"<<endl; cout<<(cur+1)<< " "<<(cur+1)<<endl; }else { if(!dfs(cur,-1,g)) { cout<<"NO"<<endl; }else { cout<<"YES"<<endl; for (int i = 0; i < res.size()-1; ++i) { cout<<res[i]+1<<" "; if(b[i]) cout<<res[i]+1<<" "; } cout<<res[res.size()-1]+1; if(b[res.size()-1]) cout<<" "<<res[res.size()-1]+1; cout<<endl; } } }

Compilation message (stderr)

newspapers.cpp: In function 'int main()':
newspapers.cpp:65:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |             for (int i = 0; i < res.size()-1; ++i) {
      |                             ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...