제출 #297205

#제출 시각아이디문제언어결과실행 시간메모리
297205PeppaPigNetwork (BOI15_net)C++14
0 / 100
10 ms12032 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() - i - 1]); if(ans.size() & 1) printf("%d %d\n", ans[0], ans[ans.size() / 2]); return 0; }

컴파일 시 표준 에러 (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...