# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
23242 | jjwdi0 | Network (BOI15_net) | C++11 | 6 ms | 14224 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;
int N;
vector<int> v[500005], ans;
bool leaf[500005];
void dfs(int x, int p) {
for(int it : v[x]) {
if(it == p) continue;
dfs(it, x);
}
if((int)v[x].size() == 1) leaf[x] = 1;
}
int main() {
scanf("%d", &N);
for(int i=1, x, y; i<N; i++) {
scanf("%d %d", &x, &y);
v[x].push_back(y);
v[y].push_back(x);
}
for(int i=1; i<=N; i++) if(v[i].size() > 1) { dfs(i, 0); break; }
for(int i=1; i<=N; i++) if(leaf[i]) ans.push_back(i);
printf("%d\n", (int)(ans.size() + 1) / 2);
for(int i=0; i<(ans.size() + 1) / 2; i++) printf("%d %d\n", ans[i], ans[i+ans.size()/2]);
}
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... |