Submission #76787

#TimeUsernameProblemLanguageResultExecution timeMemory
76787shoemakerjoNetwork (BOI15_net)C++14
0 / 100
13 ms12148 KiB
#include <bits/stdc++.h> using namespace std; #define maxn 500010 int n; vector<vector<int>> adj(maxn); vector<int> leaves; void dfs(int u, int p) { if (adj[u].size() == 1) leaves.push_back(u); for (int v : adj[u]) { if (v != p) dfs(v, u); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; int a, b; for (int i = 0; i < n-1; i++) { cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } for (int i = 1; i <= n; i++) { if (adj[i].size() != 1 || i == n) { dfs(i, -1); break; } } cout << (leaves.size()+1)/2 << endl; for (int i = 0; i < leaves.size()/2; i++) { cout << leaves[i] << " " << leaves[leaves.size()-i-1] << endl; } if (leaves.size() % 2) { cout << leaves[leaves.size()/2] << " " << leaves[0] << endl; } }

Compilation message (stderr)

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