# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
404611 | Aryan_Raina | Network (BOI15_net) | C++14 | 1 ms | 204 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 int int64_t
#define ld long double
#define ar array
const int INF = 1e17;
const int MOD = 1e9+7;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int N; cin >> N;
vector<int> g[N];
for (int i = 0; i < N - 1; i++) {
int a, b; cin >> a >> b; --a, --b;
g[a].push_back(b); g[b].push_back(a);
}
vector<int> leaves;
function<void(int,int)> dfs = [&](int u, int pu) {
for (int v : g[u]) if (v != pu) dfs(v, u);
if (g[u].size() == 1) leaves.push_back(u);
};
// leaves are now sorted in tout order
dfs(0, 0);
cout << (leaves.size() + 1) / 2 << '\n';
for (int i = 0; i < leaves.size()/2; i++)
cout << leaves[i] + 1 << ' ' << leaves[leaves.size() - 1 - i] + 1 << '\n';
if (leaves.size() & 1)
cout << leaves[leaves.size()/2] + 1 << ' ' << leaves[0] + 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... |