# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
85212 | Mahmoud_Adel | Network (BOI15_net) | C++14 | 14 ms | 12464 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 long long int ll;
const int N = 5e5+5;
vector<int> adj[N];
int main()
{
int n;
cin >> n;
for(int i=0; i<n-1; i++)
{
int x, y;
cin >> x >> y;
x--, y--;
adj[x].push_back(y), adj[y].push_back(x);
}
vector<int> vec;
for(int i=0; i<n; i++) if(adj[i].size() == 1) vec.push_back(i);
if(vec.size()%2)
{
cout << vec.size()/2 + 1 << endl;
cout << vec[0]+1 << " " << vec[1]+1 << endl;
for(int i=1; i<vec.size()-1; i+=2) cout << vec[i]+1 << " " << vec[i+1]+1 << endl;
}
else
{
cout << vec.size()/2 << endl;
for(int i=0; i<vec.size()-1; i+=2) cout << vec[i]+1 << " " << vec[i+1]+1 << endl;
}
}
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... |