# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
748426 | mariowong | Network (BOI15_net) | C++14 | 514 ms | 50136 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 deg[500005];
vector <int> edge[500005];
bool vis[500005];
vector <int> v;
void dfs(int x){
vis[x]=true;
if (deg[x] == 1) v.push_back(x);
for (int i=0;i<edge[x].size();i++){
if (!vis[edge[x][i]]) dfs(edge[x][i]);
}
}
int main(){
ios::sync_with_stdio(false);
int n;
cin >> n;
for (int i=1;i<n;i++){
int u,v;
cin >> u >> v;
edge[u].push_back(v);
edge[v].push_back(u);
deg[u]++; deg[v]++;
}
int cnt=0;
for (int i=1;i<=n;i++){
if (deg[i] == 1) cnt++;
}
cout << (cnt+1)/2 << "\n";
for (int i=1;i<=n;i++){
if (deg[i] > 1){
dfs(i);
break;
}
}
if (cnt%2 == 1) v.push_back(v[(int)v.size()-1]);
for (int i=0;i+(cnt+1)/2<v.size();i++){
cout << v[i] << " " << v[i+(cnt+1)/2] << "\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... |