# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
108711 | Mahdi_Jfri | Network (BOI15_net) | C++14 | 844 ms | 41416 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 pb push_back
const int maxn = 5e5 + 20;
vector<int> adj[maxn] , tmp;
void dfs(int v , int p = -1)
{
if((int)adj[v].size() == 1)
tmp.pb(v);
for(auto u : adj[v])
if(u != p)
dfs(u , v);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for(int i = 0; i < n - 1; i++)
{
int a , b;
cin >> a >> b;
a-- , b--;
adj[a].pb(b);
adj[b].pb(a);
}
int root = -1;
for(int i = 0; i < n; i++)
if((int)adj[i].size() != 1)
{
root = i;
dfs(i);
break;
}
int k = tmp.size();
cout << (k + 1) / 2 << endl;
for(int i = 0; i < (k + 1) / 2; i++)
cout << tmp[i] + 1 << " " << tmp[i + k / 2] + 1 << 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... |