Submission #480854

#TimeUsernameProblemLanguageResultExecution timeMemory
480854PoPularPlusPlusNetwork (BOI15_net)C++17
100 / 100
495 ms47756 KiB
#include <bits/stdc++.h> using namespace std; int N; vector<int> v[500005], ans; void dfs(int x, int p) { for(int it : v[x]) { if(it == p) continue; dfs(it, x); } if((int)v[x].size() == 1) ans.push_back(x); } int main() { scanf("%d", &N); for(int i=1, x, y; i<N; i++) { scanf("%d %d", &x, &y); v[x].push_back(y); v[y].push_back(x); } for(int i=1; i<=N; i++) if(v[i].size() > 1) { dfs(i, 0); break; } printf("%d\n", (ans.size() + 1) / 2); for(int i=0; i<(ans.size() + 1) / 2; i++) printf("%d %d\n", ans[i], ans[i+ans.size()/2]); }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:23:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   23 |     printf("%d\n", (ans.size() + 1) / 2);
      |             ~^     ~~~~~~~~~~~~~~~~~~~~
      |              |                      |
      |              int                    std::vector<int>::size_type {aka long unsigned int}
      |             %ld
net.cpp:24:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i=0; i<(ans.size() + 1) / 2; i++) printf("%d %d\n", ans[i], ans[i+ans.size()/2]);
      |                  ~^~~~~~~~~~~~~~~~~~~~~
net.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
net.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...