# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
151228 | Charis02 | Network (BOI15_net) | C++14 | 18 ms | 14712 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<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 300004
#define INF 1e9+7
using namespace std;
ll n,a,b;
vector < vector < ll > > graph(N);
vector < ll > res;
void dfs(ll cur,ll par)
{
if(graph[cur].size() == 1)
{
res.push_back(cur);
}
rep(i,0,graph[cur].size())
{
if(graph[cur][i] == par)
continue;
dfs(graph[cur][i],cur);
}
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin >> n;
rep(i,0,n-1)
{
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
}
dfs(1,1);
ll half = res.size()/2 + res.size()%2;
ll sz = res.size();
cout << half << endl;
rep(i,0,half)
{
cout << res[i] << " "<< res[(i+half)%sz] << "\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... |