#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod (10*10*10*10*10*10*10*10*10+7)
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n;
vector<ll>g[200005];
vector<ll>leaf;
void dfs(ll node,ll par){
if(g[node].size()==1){
leaf.pb(node);
}
for(auto it : g[node]){
if(it==par){
continue;
}else {
//cnt++;
dfs(it,node);
}
}
}
int32_t main(){
CODE_START;
cin>>n;
for(ll i=1;i<=n-1;i++)
{
ll x,y;
cin>>x>>y;
g[x].pb(y);
g[y].pb(x);
}
ll cnt=0;
for(ll i=1;i<=n;i++)
{
if(g[i].size()!=1){
dfs(i,0);
break;
}
}
cout<<(leaf.size()+1)/2<<endl;
for(ll i=0;i<leaf.size()/2;i++)
{
cout<<leaf[i]<<' '<<leaf[i+leaf.size()/2]<<endl;
}
if(leaf.size()%2){
cout<<leaf[0]<<' '<<leaf.back()<<endl;
}
}
Compilation message
net.cpp: In function 'int32_t main()':
net.cpp:56:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(ll i=0;i<leaf.size()/2;i++)
| ~^~~~~~~~~~~~~~
net.cpp:47:4: warning: unused variable 'cnt' [-Wunused-variable]
47 | ll cnt=0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4972 KB |
Output is correct |
2 |
Correct |
4 ms |
4972 KB |
Output is correct |
3 |
Correct |
4 ms |
4972 KB |
Output is correct |
4 |
Correct |
3 ms |
4972 KB |
Output is correct |
5 |
Correct |
4 ms |
4972 KB |
Output is correct |
6 |
Correct |
4 ms |
4972 KB |
Output is correct |
7 |
Correct |
4 ms |
4972 KB |
Output is correct |
8 |
Correct |
4 ms |
4972 KB |
Output is correct |
9 |
Correct |
4 ms |
4972 KB |
Output is correct |
10 |
Correct |
4 ms |
5100 KB |
Output is correct |
11 |
Correct |
4 ms |
4972 KB |
Output is correct |
12 |
Correct |
4 ms |
4972 KB |
Output is correct |
13 |
Correct |
4 ms |
4972 KB |
Output is correct |
14 |
Correct |
4 ms |
5120 KB |
Output is correct |
15 |
Correct |
4 ms |
4972 KB |
Output is correct |
16 |
Correct |
4 ms |
4972 KB |
Output is correct |
17 |
Correct |
4 ms |
4972 KB |
Output is correct |
18 |
Correct |
4 ms |
4972 KB |
Output is correct |
19 |
Correct |
5 ms |
4972 KB |
Output is correct |
20 |
Correct |
4 ms |
4972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4972 KB |
Output is correct |
2 |
Correct |
4 ms |
4972 KB |
Output is correct |
3 |
Correct |
4 ms |
4972 KB |
Output is correct |
4 |
Correct |
3 ms |
4972 KB |
Output is correct |
5 |
Correct |
4 ms |
4972 KB |
Output is correct |
6 |
Correct |
4 ms |
4972 KB |
Output is correct |
7 |
Correct |
4 ms |
4972 KB |
Output is correct |
8 |
Correct |
4 ms |
4972 KB |
Output is correct |
9 |
Correct |
4 ms |
4972 KB |
Output is correct |
10 |
Correct |
4 ms |
5100 KB |
Output is correct |
11 |
Correct |
4 ms |
4972 KB |
Output is correct |
12 |
Correct |
4 ms |
4972 KB |
Output is correct |
13 |
Correct |
4 ms |
4972 KB |
Output is correct |
14 |
Correct |
4 ms |
5120 KB |
Output is correct |
15 |
Correct |
4 ms |
4972 KB |
Output is correct |
16 |
Correct |
4 ms |
4972 KB |
Output is correct |
17 |
Correct |
4 ms |
4972 KB |
Output is correct |
18 |
Correct |
4 ms |
4972 KB |
Output is correct |
19 |
Correct |
5 ms |
4972 KB |
Output is correct |
20 |
Correct |
4 ms |
4972 KB |
Output is correct |
21 |
Correct |
4 ms |
4972 KB |
Output is correct |
22 |
Correct |
5 ms |
5248 KB |
Output is correct |
23 |
Correct |
5 ms |
5228 KB |
Output is correct |
24 |
Correct |
5 ms |
5248 KB |
Output is correct |
25 |
Correct |
4 ms |
5228 KB |
Output is correct |
26 |
Correct |
4 ms |
5100 KB |
Output is correct |
27 |
Correct |
4 ms |
5228 KB |
Output is correct |
28 |
Correct |
5 ms |
5228 KB |
Output is correct |
29 |
Correct |
4 ms |
5100 KB |
Output is correct |
30 |
Correct |
5 ms |
4992 KB |
Output is correct |
31 |
Correct |
5 ms |
5228 KB |
Output is correct |
32 |
Correct |
4 ms |
4972 KB |
Output is correct |
33 |
Correct |
4 ms |
4972 KB |
Output is correct |
34 |
Correct |
4 ms |
4972 KB |
Output is correct |
35 |
Correct |
4 ms |
4972 KB |
Output is correct |
36 |
Correct |
4 ms |
4972 KB |
Output is correct |
37 |
Correct |
4 ms |
5100 KB |
Output is correct |
38 |
Correct |
4 ms |
5100 KB |
Output is correct |
39 |
Correct |
4 ms |
4972 KB |
Output is correct |
40 |
Correct |
4 ms |
5120 KB |
Output is correct |
41 |
Correct |
4 ms |
5100 KB |
Output is correct |
42 |
Correct |
4 ms |
5100 KB |
Output is correct |
43 |
Correct |
4 ms |
5100 KB |
Output is correct |
44 |
Correct |
3 ms |
4972 KB |
Output is correct |
45 |
Correct |
4 ms |
5100 KB |
Output is correct |
46 |
Correct |
4 ms |
5228 KB |
Output is correct |
47 |
Correct |
5 ms |
4972 KB |
Output is correct |
48 |
Correct |
4 ms |
5100 KB |
Output is correct |
49 |
Correct |
5 ms |
5100 KB |
Output is correct |
50 |
Correct |
4 ms |
4972 KB |
Output is correct |
51 |
Correct |
4 ms |
4972 KB |
Output is correct |
52 |
Correct |
4 ms |
5100 KB |
Output is correct |
53 |
Correct |
4 ms |
5100 KB |
Output is correct |
54 |
Correct |
4 ms |
4972 KB |
Output is correct |
55 |
Correct |
4 ms |
5100 KB |
Output is correct |
56 |
Correct |
5 ms |
4972 KB |
Output is correct |
57 |
Correct |
4 ms |
5100 KB |
Output is correct |
58 |
Correct |
5 ms |
5228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4972 KB |
Output is correct |
2 |
Correct |
4 ms |
4972 KB |
Output is correct |
3 |
Correct |
4 ms |
4972 KB |
Output is correct |
4 |
Correct |
3 ms |
4972 KB |
Output is correct |
5 |
Correct |
4 ms |
4972 KB |
Output is correct |
6 |
Correct |
4 ms |
4972 KB |
Output is correct |
7 |
Correct |
4 ms |
4972 KB |
Output is correct |
8 |
Correct |
4 ms |
4972 KB |
Output is correct |
9 |
Correct |
4 ms |
4972 KB |
Output is correct |
10 |
Correct |
4 ms |
5100 KB |
Output is correct |
11 |
Correct |
4 ms |
4972 KB |
Output is correct |
12 |
Correct |
4 ms |
4972 KB |
Output is correct |
13 |
Correct |
4 ms |
4972 KB |
Output is correct |
14 |
Correct |
4 ms |
5120 KB |
Output is correct |
15 |
Correct |
4 ms |
4972 KB |
Output is correct |
16 |
Correct |
4 ms |
4972 KB |
Output is correct |
17 |
Correct |
4 ms |
4972 KB |
Output is correct |
18 |
Correct |
4 ms |
4972 KB |
Output is correct |
19 |
Correct |
5 ms |
4972 KB |
Output is correct |
20 |
Correct |
4 ms |
4972 KB |
Output is correct |
21 |
Correct |
4 ms |
4972 KB |
Output is correct |
22 |
Correct |
5 ms |
5248 KB |
Output is correct |
23 |
Correct |
5 ms |
5228 KB |
Output is correct |
24 |
Correct |
5 ms |
5248 KB |
Output is correct |
25 |
Correct |
4 ms |
5228 KB |
Output is correct |
26 |
Correct |
4 ms |
5100 KB |
Output is correct |
27 |
Correct |
4 ms |
5228 KB |
Output is correct |
28 |
Correct |
5 ms |
5228 KB |
Output is correct |
29 |
Correct |
4 ms |
5100 KB |
Output is correct |
30 |
Correct |
5 ms |
4992 KB |
Output is correct |
31 |
Correct |
5 ms |
5228 KB |
Output is correct |
32 |
Correct |
4 ms |
4972 KB |
Output is correct |
33 |
Correct |
4 ms |
4972 KB |
Output is correct |
34 |
Correct |
4 ms |
4972 KB |
Output is correct |
35 |
Correct |
4 ms |
4972 KB |
Output is correct |
36 |
Correct |
4 ms |
4972 KB |
Output is correct |
37 |
Correct |
4 ms |
5100 KB |
Output is correct |
38 |
Correct |
4 ms |
5100 KB |
Output is correct |
39 |
Correct |
4 ms |
4972 KB |
Output is correct |
40 |
Correct |
4 ms |
5120 KB |
Output is correct |
41 |
Correct |
4 ms |
5100 KB |
Output is correct |
42 |
Correct |
4 ms |
5100 KB |
Output is correct |
43 |
Correct |
4 ms |
5100 KB |
Output is correct |
44 |
Correct |
3 ms |
4972 KB |
Output is correct |
45 |
Correct |
4 ms |
5100 KB |
Output is correct |
46 |
Correct |
4 ms |
5228 KB |
Output is correct |
47 |
Correct |
5 ms |
4972 KB |
Output is correct |
48 |
Correct |
4 ms |
5100 KB |
Output is correct |
49 |
Correct |
5 ms |
5100 KB |
Output is correct |
50 |
Correct |
4 ms |
4972 KB |
Output is correct |
51 |
Correct |
4 ms |
4972 KB |
Output is correct |
52 |
Correct |
4 ms |
5100 KB |
Output is correct |
53 |
Correct |
4 ms |
5100 KB |
Output is correct |
54 |
Correct |
4 ms |
4972 KB |
Output is correct |
55 |
Correct |
4 ms |
5100 KB |
Output is correct |
56 |
Correct |
5 ms |
4972 KB |
Output is correct |
57 |
Correct |
4 ms |
5100 KB |
Output is correct |
58 |
Correct |
5 ms |
5228 KB |
Output is correct |
59 |
Runtime error |
10 ms |
9964 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
60 |
Halted |
0 ms |
0 KB |
- |