Submission #672870

#TimeUsernameProblemLanguageResultExecution timeMemory
672870iosif_andrei_Network (BOI15_net)C++14
0 / 100
8 ms12044 KiB
#include <bits/stdc++.h> using namespace std; int n; vector <int> g[500001]; vector <int> v; int main() { cin >> n; for (int i = 1; i < n; i++) { int x, y; cin >> x >> y; g[x].push_back(y); g[y].push_back(x); } for (int i = 1; i <= n; i++) if (g[i].size() == 1) v.push_back(i); cout << (v.size() + 1) / 2 << '\n'; for (int i = 0; i < v.size() - 1; i += 2) cout << v[i] << ' ' << v[i + 1] << '\n'; if (v.size() % 2) if (g[v.back()].back() == 1) cout << v.back() << ' ' << 2; else cout << v.back() << ' ' << 1; return 0; }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:26:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for (int i = 0; i < v.size() - 1; i += 2)
      |                     ~~^~~~~~~~~~~~~~
net.cpp:29:8: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   29 |     if (v.size() % 2)
      |        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...