Submission #297206

#TimeUsernameProblemLanguageResultExecution timeMemory
297206PeppaPigNetwork (BOI15_net)C++14
100 / 100
581 ms47732 KiB
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; int n; vector<int> g[N], ans; void dfs(int u, int p) { if(g[u].size() == 1) ans.emplace_back(u); for(int v : g[u]) if(v != p) dfs(v, u); } int main() { scanf("%d", &n); for(int i = 1, a, b; i < n; i++) { scanf("%d %d", &a, &b); g[a].emplace_back(b); g[b].emplace_back(a); } for(int i = 1; i <= n; i++) if(g[i].size() != 1) { dfs(i, 0); break; } printf("%d\n", (ans.size() + 1) / 2); for(int i = 0; i < ans.size() / 2; i++) printf("%d %d\n", ans[i], ans[ans.size() / 2 + i]); if(ans.size() & 1) printf("%d %d\n", ans[0], ans.back()); return 0; }

Compilation message (stderr)

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