제출 #291596

#제출 시각아이디문제언어결과실행 시간메모리
291596FischerNetwork (BOI15_net)C++14
100 / 100
917 ms52120 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; vector<int> g[maxn]; int n; void dfs(vector<int>& nodes, int x, int p=0) { if (g[x].size() == 1) nodes.emplace_back(x); for (int v : g[x]) { if (v==p) continue; dfs(nodes, v, x); } } int main() { scanf("%d", &n); for (int i=0; i<n-1; ++i) { int a, b; scanf("%d%d", &a, &b); g[a].emplace_back(b); g[b].emplace_back(a); } vector<int> nodes; dfs(nodes, 1); cout << (nodes.size() + 1) / 2 << endl; for (int i = 0; i < nodes.size() / 2; ++i) { cout << nodes[i] << " " << nodes[(nodes.size() + 1) / 2 + i] << endl; } if (nodes.size() & 1) cout << 1 << " " << nodes[nodes.size() / 2] << endl; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

net.cpp: In function 'int main()':
net.cpp:27:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for (int i = 0; i < nodes.size() / 2; ++i) {
      |                     ~~^~~~~~~~~~~~~~~~~~
net.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
net.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |         scanf("%d%d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...