# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
482470 | Saacoota | Network (BOI15_net) | C++14 | 431 ms | 66836 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
vector < int > g[maxn] , leaf;
int cnt[maxn] , par[maxn];
void DFS(int u,int p) {
if (g[u].size() == 1) leaf.push_back(u);
for (auto v : g[u])
if (v != p) {
par[v] = u;
DFS(v , u);
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n , root;
cin >> n;
for (int i = 1 ; i < n ; ++i) {
int u , v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
if (g[u].size() > 1) root = u;
if (g[v].size() > 1) root = v;
}
DFS(root , 0);
int half = leaf.size() / 2;
cout << (leaf.size() + 1) / 2 << '\n';
for (int j = 0 ; j < (leaf.size() + 1) / 2 ; ++j)
cout << leaf[j] << ' ' << leaf[half + j] << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |