# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
95937 | luciocf | Network (BOI15_net) | C++14 | 857 ms | 65600 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;
const int maxn = 5e5+10;
typedef pair<int, int> pii;
int leaf[maxn], tt;
vector<int> grafo[maxn];
void dfs(int u, int p)
{
for (auto v: grafo[u])
{
if (v == p) continue;
dfs(v, u);
}
if (grafo[u].size() == 1) leaf[++tt] = u;
}
int main(void)
{
int n;
cin >> n;
for (int i = 1; i < n; i++)
{
int u, v;
cin >> u >> v;
grafo[u].push_back(v);
grafo[v].push_back(u);
}
int root;
for (int i = 1; i <= n; i++)
if (grafo[i].size() > 1) root = i;
dfs(root, 0);
int ans = (tt+1)/2;
cout << ans << "\n";
for (int i = 1; i < ans; i++)
cout << leaf[i] << " " << leaf[i+ans] << "\n";
if (tt&1) cout << leaf[ans] << " " << leaf[1] << "\n";
else cout << leaf[ans] << " " << leaf[tt] << "\n";
}
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... |