Submission #546403

#TimeUsernameProblemLanguageResultExecution timeMemory
546403yutabiNewspapers (CEOI21_newspapers)C++14
8 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back int n,m; int start; vector <vector <int> > tree; vector <int> ans; int main() { scanf("%d %d",&n,&m); if(n==1) { printf("YES\n1\n1"); return 0; } if(n==2) { printf("YES\n2\n1 1"); return 0; } if(m>=n) { printf("NO"); return 0; } tree=vector <vector <int> > (n); for(int i=0;i<m;i++) { int a,b; scanf(" %d %d",&a,&b); a--,b--; tree[a].pb(b); tree[b].pb(a); } for(int i=0;i<n;i++) { if(tree[i].size()==1) { continue; } int a=0; for(int j=0;j<tree[i].size();j++) { if(tree[tree[i][j]].size()!=1) { a++; } } if(a<2) { start=i; } if(a>2) { printf("NO"); return 0; } } int curr=start; int last=-1; while(1) { if(ans.size() && ans.back()==curr) { break; } ans.pb(curr); for(int i=0;i<tree[curr].size();i++) { if(tree[curr][i]!=last && tree[tree[curr][i]].size()!=1) { last=curr; curr=tree[curr][i]; break; } } } printf("YES\n%d\n",ans.size()*2); for(int i=0;i<ans.size();i++) { printf("%d ",ans[i]+1); } for(int i=ans.size()-1;i>=0;i--) { printf("%d ",ans[i]+1); } }

Compilation message (stderr)

newspapers.cpp: In function 'int main()':
newspapers.cpp:62:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         for(int j=0;j<tree[i].size();j++)
      |                     ~^~~~~~~~~~~~~~~
newspapers.cpp:95:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |         for(int i=0;i<tree[curr].size();i++)
      |                     ~^~~~~~~~~~~~~~~~~~
newspapers.cpp:108:19: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
  108 |     printf("YES\n%d\n",ans.size()*2);
      |                  ~^    ~~~~~~~~~~~~
      |                   |              |
      |                   int            std::vector<int>::size_type {aka long unsigned int}
      |                  %ld
newspapers.cpp:110:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |     for(int i=0;i<ans.size();i++)
      |                 ~^~~~~~~~~~~
newspapers.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
newspapers.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         scanf(" %d %d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...