# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
823021 | serifefedartar | Network (BOI15_net) | C++17 | 371 ms | 47664 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 fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MOD 1000000009
#define LOGN 20
#define MAXN 2000100
vector<vector<int>> graph;
vector<int> leaves;
void dfs(int node, int parent) {
if (graph[node].size() == 1)
leaves.push_back(node);
for (auto u : graph[node]) {
if (u == parent)
continue;
dfs(u, node);
}
}
int main() {
fast
int n, u, v;
cin >> n;
graph = vector<vector<int>>(n+1, vector<int>());
for (int i = 1; i < n; i++) {
cin >> u >> v;
graph[u].push_back(v);
graph[v].push_back(u);
}
dfs(1, 1);
cout << (leaves.size()+1) / 2 << "\n";
for (int i = 0; i < (leaves.size()+1)/2; i++) {
cout << leaves[i] << " " << leaves[i + leaves.size()/2] << "\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... |