# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
497284 | aryan12 | Network (BOI15_net) | C++17 | 454 ms | 48628 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 long long
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
const int N = 5e5 + 5;
vector<int> g[N];
vector<int> leaves;
void dfs(int node, int par) {
if(g[node].size() == 1) {
leaves.push_back(node);
}
for(int i = 0; i < g[node].size(); i++) {
if(g[node][i] == par) {
continue;
}
dfs(g[node][i], node);
}
}
void Solve() {
int n;
cin >> n;
for(int i = 1; i < n; i++) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
dfs(1, -1);
int x = leaves.size();
cout << (x + 1) / 2 << "\n";
leaves.push_back(1);
x++;
for(int i = 0; i < x / 2; i++) {
cout << leaves[i] << " " << leaves[i + x / 2] << "\n";
}
}
int32_t main() {
auto begin = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
while(t--) {
Solve();
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
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... |