# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
655934 | aebov | Network (BOI15_net) | C++17 | 7 ms | 12004 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<iostream>
#include<vector>
#include<cstring>
#include<utility>
#define pb push_back
#define pii pair<int, int>
#define F first
#define S second
using namespace std;
const int N = (int)5e5 + 5;
int n , u, v, d[N];
vector<int> leafs;
vector<pii> ret;
vector<int> adj[N];
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 1; i < n ; i ++){
cin >> u >> v;
d[u] ++, d[v] ++;
}
for(int i = 1; i <= n; i ++)if(d[i] == 1)leafs.pb(i);
if(leafs.size() & 1){
if(leafs[0] == 1)ret.pb({1, n});
else ret.pb({leafs[0], 1});
for(int i = 1; i < leafs.size();i += 2)ret.pb({leafs[i], leafs[i+1]});
}
else{
for(int i = 0; i < leafs.size(); i += 2)ret.pb({leafs[i], leafs[i+1]});
}
cout << ret.size() << endl;
for(auto [x, y] : ret)cout << x << " " << y << endl;
}
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... |