# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
546669 | Jomnoi | Network (BOI15_net) | C++17 | 401 ms | 47676 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>
#define DEBUG 0
using namespace std;
const int N = 5e5 + 10;
vector <int> adj[N];
vector <int> leaf;
void dfs(int u, int p) {
if(adj[u].size() == 1) {
leaf.push_back(u);
}
for(auto v : adj[u]) {
if(v != p) {
dfs(v, u);
}
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
for(int i = 1; i <= n - 1; i++) {
int a, b;
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) {
dfs(1, -1);
break;
}
}
cout << (leaf.size() + 1) / 2 << '\n';
for(int i = 0; i < (leaf.size() + 1) / 2; i++) {
cout << leaf[i] << ' ' << leaf[leaf.size() / 2 + i] << '\n';
}
return 0;
}
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... |