Submission #71441

#TimeUsernameProblemLanguageResultExecution timeMemory
71441GoogalNetwork (BOI15_net)C++14
100 / 100
792 ms155572 KiB
#include <iostream> #include <vector> using namespace std; const int NMAX = 6 * 1e5 + 1e2; int n; int startn; vector < int > g[1 + NMAX]; vector < int > res; void dfs(int u, int v) { if(g[u].size() == 1) { res.push_back(u); return; } for(int i = 0; i < g[u].size(); i++) { if(g[u][i] == v) continue; dfs(g[u][i], u); } } int main() { ios::sync_with_stdio(false); 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() >= 2) { startn = i; break; } } dfs(startn, -1); int rsize = res.size(); cout << rsize / 2 + rsize % 2 << '\n'; for(int i = 0; i + rsize / 2 < rsize; i++) cout << res[i] << ' ' << res[i + rsize / 2] << '\n'; return 0; }

Compilation message (stderr)

net.cpp: In function 'void dfs(int, int)':
net.cpp:20:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < g[u].size(); i++) {
                  ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...