-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.cpp
55 lines (52 loc) · 957 Bytes
/
C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0);cin.tie(0)
long long deg[100005],cnt[100005],mx;
int main()
{
fastio;
long long n,i,j,u,v;
cin>>n;
for(i=0;i<n-1;i++)
{
cin>>u>>v;
deg[u]++;
deg[v]++;
}
for(i=1;i<=n;i++)
{
mx=max(mx,deg[i]);
cnt[deg[i]]++;
}
if(cnt[1]==2 && cnt[2]==n-2)
{
cout<<"Yes\n1\n";
for(i=1;i<=n;i++)
{
if(deg[i]==1)
cout<<i<<" ";
}
cout<<"\n";
}
else if(cnt[1]==mx)
{
cout<<"Yes\n"<<mx<<"\n";
long long r;
for(i=1;i<=n;i++)
{
if(deg[i]==mx)
{
r=i;
break;
}
}
for(i=1;i<=n;i++)
{
if(deg[i]==1)
cout<<r<<" "<<i<<"\n";
}
}
else
cout<<"No\n";
return 0;
}