# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
95927 | luciocf | Network (BOI15_net) | C++14 | 10 ms | 12152 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;
vector<int> grafo[maxn];
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 ans = 0, first;
deque<int> leaf;
for (int i = 1; i <= n; i++)
if (grafo[i].size() == 1)
leaf.push_back(i), ans++, first = i;
cout << (ans+1)/2 << "\n";
while (leaf.size() > 0)
{
if (leaf.size() > 1)
{
cout << leaf.back() << " " << leaf.front() << "\n";
leaf.pop_back(), leaf.pop_front();
}
else
{
cout << leaf.back() << " " << first << "\n";
leaf.pop_back();
}
}
}
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... |