# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1084613 | _rain_ | Network (BOI15_net) | C++14 | 201 ms | 47824 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;
#define ll long long
#define fixbug true
const int maxn = 5e5;
vector<int> g[maxn+2];
vector<int> leaf;
int n;
void dfs(int u , int p){
if (g[u].size()==1) leaf.push_back(u);
for (auto& v : g[u]){
if (v != p) dfs(v,u);
}
return;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
#define name "main"
if (fopen(name".inp","r")){
freopen(name".inp","r",stdin);
}
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);
}
for (int i = 1; i <= n; ++i){
if (g[i].size() > 1){
dfs(i,i);
break;
}
}
if (leaf.size()%2==1) leaf.push_back(leaf.front());
cout << leaf.size() / 2 << '\n';
for (int i = 0; i < leaf.size() / 2; i++){
cout << leaf[i] << ' ' << leaf[leaf.size()/2 + i] << '\n';
}
exit(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... |