# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
59637 | IvanC | Network (BOI15_net) | C++17 | 754 ms | 153032 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 = 5*1e5 + 10;
vector<int> grafo[MAXN],folhas;
int N;
void dfs(int v,int p){
if(grafo[v].size() == 1) folhas.push_back(v);
for(int u : grafo[v]) if(u != p) dfs(u,v);
}
int main(){
scanf("%d",&N);
for(int i = 1;i<N;i++){
int u,v;
scanf("%d %d",&u,&v);
grafo[u].push_back(v);
grafo[v].push_back(u);
}
dfs(1,-1);
int ans = (folhas.size() + 1)/2;
int delta = (folhas.size())/2;
printf("%d\n",ans);
for(int i = 0;i<ans;i++){
printf("%d %d\n",folhas[i],folhas[i + delta]);
}
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... |