# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
24944 | RezwanArefin01 | Network (BOI15_net) | C++14 | 623 ms | 42508 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.
//Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 5e5;
vector<int> adj[maxn], lef;
void dfs(int u, int par){
for(int v : adj[u]) if(v - par) dfs(v, u);
if(adj[u].size() == 1) lef.push_back(u);
}
int main(int argc, char const *argv[]) {
#ifdef LOCAL_TESTING
freopen("in", "r", stdin);
#endif
int n; scanf("%d", &n);
for(int i=0; i<n-1; i++) {
int u, v;
scanf("%d %d", &u, &v);
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i=1; i<=n; i++) if(adj[i].size() > 1) {
dfs(i, 0); break;
}
int sz = int((lef.size()+1)/2);
printf("%d\n", sz);
for(int i=0; i<sz; i++) {
printf("%d %d\n", lef[i], lef[i + lef.size()/2]);
}
}
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... |