# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
57859 | IvanC | Network (BOI15_net) | C++17 | 3 ms | 728 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;
typedef pair<int,int> ii;
const int MAXN = 5*1e5 + 10;
int grau[MAXN],N;
vector<int> raizes;
vector<ii> pares;
int main(){
scanf("%d",&N);
for(int i = 1;i<N;i++){
int a,b;
scanf("%d %d",&a,&b);
grau[a]++;
grau[b]++;
}
for(int i = 1;i<=N;i++){
if(grau[i] == 1) raizes.push_back(i);
}
if(raizes.size() % 2 == 1) raizes.push_back(raizes[0]);
while(!raizes.empty()){
int a = raizes.back();
raizes.pop_back();
int b = raizes.back();
raizes.pop_back();
pares.push_back(ii(a,b));
}
printf("%d\n", (int)pares.size() );
for(ii davez : pares){
printf("%d %d\n",davez.first,davez.second);
}
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... |