| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1368071 | SmuggingSpun | Network (BOI15_net) | C++20 | 170 ms | 37176 KiB |
#include<bits/stdc++.h>
#define taskname "C"
using namespace std;
const int lim = 5e5 + 5;
int n, tdfs = 0, low[lim];
vector<int>g[lim];
void dfs(int s, int p = -1){
low[s] = ++tdfs;
for(int& d : g[s]){
if(d != p){
dfs(d, s);
}
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
cin >> n;
for(int i = 1; i < n; i++){
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1);
vector<int>leaf;
for(int i = 1; i <= n; i++){
if(g[i].size() == 1){
leaf.push_back(i);
}
}
sort(leaf.begin(), leaf.end(), [&] (int i, int j){
return low[i] < low[j];
});
cout << (int(leaf.size() + 1) >> 1) << "\n";
for(int i = 0; i < (int(leaf.size() + 1) >> 1); i++){
cout << leaf[i] << " " << leaf[i + (int(leaf.size()) >> 1)] << "\n";
}
}
Compilation message (stderr)
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
