# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
638397 |
2022-09-05T19:15:52 Z |
xad |
Network (BOI15_net) |
C++14 |
|
1 ms |
212 KB |
#include <bits/stdc++.h>
using namespace std ;
#define nn "\n"
#define x_x ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define intt int t; cin>>t; while(t--)
#define emp emplace_back
#define mod 1000000007
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
//#define a first
//#define b second
typedef long long ll;
int main()
{
x_x
int n; cin>>n; vector<int>adj[n+2]; vector<pair<int,int>>v,ch; int p[n+2];
for(int i=1,x,y; i<n; i++)cin>>x>>y, adj[x].emp(y), adj[y].emp(x),p[x]=y,p[y]=x;
for(int i=1; i<=n; i++)
if(sz(adj[i])==1)
{
ch.push_back({p[i],i});
}
sort(all(ch));
if(ch[0].first==ch.back().first)
{
cout<<sz(ch)/2+(sz(ch)%2)<<nn;
for(int i=0; i<sz(ch)-1; i+=2)cout<<ch[i].second<<' '<<ch[i+1].second<<nn;
if(sz(ch)%2)cout<<ch[0].second<<' '<<ch.back().second;
}
else
{
for(int i=0,j=0; i<sz(ch); i++)
{
if(!ch[i].first)continue;
while(ch[j].first==ch[i].first)j=(j+1)%sz(ch);
v.push_back({ch[i].second,ch[j].second}); ch[i].first=ch[j].first=0; j=(j+1)%sz(ch);
}
cout<<sz(v)<<nn;
for(auto i:v)cout<<i.first<< ' '<<i.second<<nn;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Invalid number of links. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Invalid number of links. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Invalid number of links. |
3 |
Halted |
0 ms |
0 KB |
- |