# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
79683 | EntityIT | Network (BOI15_net) | C++14 | 737 ms | 42312 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 pb push_back
#define fi first
#define se second
typedef pair<int, int> ii;
const int N = 5e5 + 5;
int n, nLeaf;
vector<int> gr[N], vec;
void dfs (int u, int p) {
for (int v : gr[u]) if (v != p) dfs(v, u);
if (gr[u].size() == 1) vec.pb(u);
}
int main () {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for (int _ = 1; _ < n; ++_) {
int u, v; cin >> u >> v;
gr[u].pb(v); gr[v].pb(u);
}
for (int u = 1; u <= n; ++u) nLeaf += (gr[u].size() == 1);
cout << (nLeaf + 1) / 2 << '\n';
for (int u = 1; u <= n; ++u) if (gr[u].size() > 1) {
dfs(u, u);
break ;
}
for (int i = 0; i < vec.size() - (nLeaf + 1) / 2; ++i) cout << vec[i] << ' ' << vec[i + (nLeaf + 1) / 2] << '\n';
if (nLeaf % 2) cout << vec[0] << ' ' << vec[nLeaf / 2];
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... |