# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
95940 | luciocf | Network (BOI15_net) | C++14 | 12 ms | 12024 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;
vector<int> grafo[maxn], leaf;
int main(void)
{
srand(1001234545);
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;
else leaf.push_back(i);
}
if (leaf.size()&1) leaf.push_back(root);
int ans = leaf.size()/2;
random_shuffle(leaf.begin(), leaf.end());
cout << ans << "\n";
for (int i = 0; i < leaf.size(); i += 2)
cout << leaf[i] << " " << leaf[i+1] << "\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... |