# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
533815 | groshi | Network (BOI15_net) | C++17 | 359 ms | 47672 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<iostream>
#include<vector>
using namespace std;
struct wi{
vector<int> Q;
}*w;
vector<int> mam;
void dfs(int x,int ojc)
{
if(w[x].Q.size()==1)
mam.push_back(x);
for(int i=0;i<w[x].Q.size();i++)
{
int pom=w[x].Q[i];
if(pom==ojc)
continue;
dfs(pom,x);
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,x,y;
cin>>n;
w=new wi[n+3];
for(int i=1;i<n;i++)
{
cin>>x>>y;
w[x].Q.push_back(y);
w[y].Q.push_back(x);
}
for(int i=1;i<=n;i++)
{
if(w[i].Q.size()>1)
{
dfs(i,0);
break;
}
}
cout<<(mam.size()+1)/2<<"\n";
for(int i=0;i<(mam.size()+1)/2;i++)
cout<<mam[i]<<" "<<mam[i+mam.size()/2]<<"\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... |