/**
* Author: Amirrrr
* Created: 24.06.2023
* Why am I so stupid? :c
* Slishkom slab
**/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define FF first
#define SS second
#define ent "\n"
#define int long long
const int N = 5e5 + 13;
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int maxn = 1e6 + 12;
int n,x,y,used[N];
vector<int>g[N],ord;
void dfs(int v){
used[v]=1;
if(g[v].size()==1){
ord.pb(v);
}
for(auto to:g[v]){
if(!used[to]){
dfs(to);
}
}
}
void gogo (){
cin>>n;
for(int i=1;i<n;i++){
int x,y;cin>>x>>y;
g[x].pb(y),g[y].pb(x);
}
dfs(1);
cout<<(ord.size()+1)/2<<ent;
for(int i=0;i<ord.size()/2;i++){
cout<<ord[i]<<' '<<ord[i+ord.size()/2]<<ent;
}
if(ord.size()%2){
cout<<ord.back()<<' '<<ord[0]<<ent;
}
}
signed main (/*Amir Mirmanov*/){
ios_base::sync_with_stdio(0),cin.tie(0);
int Q=1,test=1;
//freopen("rain.in","r",stdin);
//freopen("rain.out","w",stdout);
//cin>>Q;
while (Q --){
gogo();
}
return 0;
}
Compilation message
net.cpp: In function 'void gogo()':
net.cpp:47:18: 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]
47 | for(int i=0;i<ord.size()/2;i++){
| ~^~~~~~~~~~~~~
net.cpp: In function 'int main()':
net.cpp:57:13: warning: unused variable 'test' [-Wunused-variable]
57 | int Q=1,test=1;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
5 ms |
12072 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
11988 KB |
Output is correct |
8 |
Correct |
5 ms |
11988 KB |
Output is correct |
9 |
Correct |
7 ms |
12116 KB |
Output is correct |
10 |
Correct |
6 ms |
11988 KB |
Output is correct |
11 |
Correct |
6 ms |
11988 KB |
Output is correct |
12 |
Correct |
6 ms |
12044 KB |
Output is correct |
13 |
Correct |
5 ms |
11988 KB |
Output is correct |
14 |
Correct |
5 ms |
11988 KB |
Output is correct |
15 |
Correct |
5 ms |
11988 KB |
Output is correct |
16 |
Correct |
5 ms |
11988 KB |
Output is correct |
17 |
Correct |
5 ms |
11988 KB |
Output is correct |
18 |
Correct |
5 ms |
11988 KB |
Output is correct |
19 |
Correct |
6 ms |
11988 KB |
Output is correct |
20 |
Correct |
5 ms |
11988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
5 ms |
12072 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
11988 KB |
Output is correct |
8 |
Correct |
5 ms |
11988 KB |
Output is correct |
9 |
Correct |
7 ms |
12116 KB |
Output is correct |
10 |
Correct |
6 ms |
11988 KB |
Output is correct |
11 |
Correct |
6 ms |
11988 KB |
Output is correct |
12 |
Correct |
6 ms |
12044 KB |
Output is correct |
13 |
Correct |
5 ms |
11988 KB |
Output is correct |
14 |
Correct |
5 ms |
11988 KB |
Output is correct |
15 |
Correct |
5 ms |
11988 KB |
Output is correct |
16 |
Correct |
5 ms |
11988 KB |
Output is correct |
17 |
Correct |
5 ms |
11988 KB |
Output is correct |
18 |
Correct |
5 ms |
11988 KB |
Output is correct |
19 |
Correct |
6 ms |
11988 KB |
Output is correct |
20 |
Correct |
5 ms |
11988 KB |
Output is correct |
21 |
Correct |
5 ms |
11988 KB |
Output is correct |
22 |
Correct |
6 ms |
12116 KB |
Output is correct |
23 |
Correct |
7 ms |
12116 KB |
Output is correct |
24 |
Correct |
6 ms |
12116 KB |
Output is correct |
25 |
Correct |
8 ms |
12116 KB |
Output is correct |
26 |
Correct |
6 ms |
12080 KB |
Output is correct |
27 |
Correct |
6 ms |
12116 KB |
Output is correct |
28 |
Correct |
6 ms |
12116 KB |
Output is correct |
29 |
Correct |
6 ms |
12116 KB |
Output is correct |
30 |
Correct |
5 ms |
11988 KB |
Output is correct |
31 |
Correct |
6 ms |
12116 KB |
Output is correct |
32 |
Correct |
6 ms |
11988 KB |
Output is correct |
33 |
Correct |
6 ms |
11988 KB |
Output is correct |
34 |
Correct |
6 ms |
11988 KB |
Output is correct |
35 |
Correct |
6 ms |
11988 KB |
Output is correct |
36 |
Correct |
6 ms |
11988 KB |
Output is correct |
37 |
Correct |
6 ms |
11988 KB |
Output is correct |
38 |
Correct |
6 ms |
12116 KB |
Output is correct |
39 |
Correct |
6 ms |
11988 KB |
Output is correct |
40 |
Correct |
6 ms |
11968 KB |
Output is correct |
41 |
Correct |
5 ms |
12068 KB |
Output is correct |
42 |
Correct |
6 ms |
11988 KB |
Output is correct |
43 |
Correct |
6 ms |
12116 KB |
Output is correct |
44 |
Correct |
6 ms |
11988 KB |
Output is correct |
45 |
Correct |
6 ms |
11988 KB |
Output is correct |
46 |
Correct |
6 ms |
12116 KB |
Output is correct |
47 |
Correct |
7 ms |
11956 KB |
Output is correct |
48 |
Correct |
6 ms |
11988 KB |
Output is correct |
49 |
Correct |
7 ms |
12116 KB |
Output is correct |
50 |
Correct |
6 ms |
11988 KB |
Output is correct |
51 |
Correct |
6 ms |
11988 KB |
Output is correct |
52 |
Correct |
6 ms |
11988 KB |
Output is correct |
53 |
Correct |
9 ms |
12244 KB |
Output is correct |
54 |
Correct |
6 ms |
11988 KB |
Output is correct |
55 |
Correct |
6 ms |
12080 KB |
Output is correct |
56 |
Correct |
6 ms |
12076 KB |
Output is correct |
57 |
Correct |
6 ms |
11988 KB |
Output is correct |
58 |
Correct |
7 ms |
12116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
5 ms |
12072 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
11988 KB |
Output is correct |
8 |
Correct |
5 ms |
11988 KB |
Output is correct |
9 |
Correct |
7 ms |
12116 KB |
Output is correct |
10 |
Correct |
6 ms |
11988 KB |
Output is correct |
11 |
Correct |
6 ms |
11988 KB |
Output is correct |
12 |
Correct |
6 ms |
12044 KB |
Output is correct |
13 |
Correct |
5 ms |
11988 KB |
Output is correct |
14 |
Correct |
5 ms |
11988 KB |
Output is correct |
15 |
Correct |
5 ms |
11988 KB |
Output is correct |
16 |
Correct |
5 ms |
11988 KB |
Output is correct |
17 |
Correct |
5 ms |
11988 KB |
Output is correct |
18 |
Correct |
5 ms |
11988 KB |
Output is correct |
19 |
Correct |
6 ms |
11988 KB |
Output is correct |
20 |
Correct |
5 ms |
11988 KB |
Output is correct |
21 |
Correct |
5 ms |
11988 KB |
Output is correct |
22 |
Correct |
6 ms |
12116 KB |
Output is correct |
23 |
Correct |
7 ms |
12116 KB |
Output is correct |
24 |
Correct |
6 ms |
12116 KB |
Output is correct |
25 |
Correct |
8 ms |
12116 KB |
Output is correct |
26 |
Correct |
6 ms |
12080 KB |
Output is correct |
27 |
Correct |
6 ms |
12116 KB |
Output is correct |
28 |
Correct |
6 ms |
12116 KB |
Output is correct |
29 |
Correct |
6 ms |
12116 KB |
Output is correct |
30 |
Correct |
5 ms |
11988 KB |
Output is correct |
31 |
Correct |
6 ms |
12116 KB |
Output is correct |
32 |
Correct |
6 ms |
11988 KB |
Output is correct |
33 |
Correct |
6 ms |
11988 KB |
Output is correct |
34 |
Correct |
6 ms |
11988 KB |
Output is correct |
35 |
Correct |
6 ms |
11988 KB |
Output is correct |
36 |
Correct |
6 ms |
11988 KB |
Output is correct |
37 |
Correct |
6 ms |
11988 KB |
Output is correct |
38 |
Correct |
6 ms |
12116 KB |
Output is correct |
39 |
Correct |
6 ms |
11988 KB |
Output is correct |
40 |
Correct |
6 ms |
11968 KB |
Output is correct |
41 |
Correct |
5 ms |
12068 KB |
Output is correct |
42 |
Correct |
6 ms |
11988 KB |
Output is correct |
43 |
Correct |
6 ms |
12116 KB |
Output is correct |
44 |
Correct |
6 ms |
11988 KB |
Output is correct |
45 |
Correct |
6 ms |
11988 KB |
Output is correct |
46 |
Correct |
6 ms |
12116 KB |
Output is correct |
47 |
Correct |
7 ms |
11956 KB |
Output is correct |
48 |
Correct |
6 ms |
11988 KB |
Output is correct |
49 |
Correct |
7 ms |
12116 KB |
Output is correct |
50 |
Correct |
6 ms |
11988 KB |
Output is correct |
51 |
Correct |
6 ms |
11988 KB |
Output is correct |
52 |
Correct |
6 ms |
11988 KB |
Output is correct |
53 |
Correct |
9 ms |
12244 KB |
Output is correct |
54 |
Correct |
6 ms |
11988 KB |
Output is correct |
55 |
Correct |
6 ms |
12080 KB |
Output is correct |
56 |
Correct |
6 ms |
12076 KB |
Output is correct |
57 |
Correct |
6 ms |
11988 KB |
Output is correct |
58 |
Correct |
7 ms |
12116 KB |
Output is correct |
59 |
Correct |
228 ms |
44016 KB |
Output is correct |
60 |
Correct |
362 ms |
47216 KB |
Output is correct |
61 |
Correct |
7 ms |
11988 KB |
Output is correct |
62 |
Correct |
6 ms |
11988 KB |
Output is correct |
63 |
Correct |
210 ms |
39864 KB |
Output is correct |
64 |
Correct |
8 ms |
12464 KB |
Output is correct |
65 |
Correct |
13 ms |
14164 KB |
Output is correct |
66 |
Correct |
77 ms |
29304 KB |
Output is correct |
67 |
Correct |
362 ms |
50804 KB |
Output is correct |
68 |
Correct |
344 ms |
52380 KB |
Output is correct |
69 |
Correct |
10 ms |
13140 KB |
Output is correct |
70 |
Correct |
60 ms |
24484 KB |
Output is correct |
71 |
Correct |
191 ms |
49708 KB |
Output is correct |
72 |
Correct |
222 ms |
48124 KB |
Output is correct |
73 |
Correct |
73 ms |
21164 KB |
Output is correct |
74 |
Correct |
296 ms |
45008 KB |
Output is correct |
75 |
Correct |
21 ms |
16068 KB |
Output is correct |
76 |
Correct |
205 ms |
49232 KB |
Output is correct |
77 |
Correct |
192 ms |
49400 KB |
Output is correct |
78 |
Correct |
29 ms |
16076 KB |
Output is correct |
79 |
Correct |
338 ms |
49072 KB |
Output is correct |
80 |
Correct |
7 ms |
12372 KB |
Output is correct |
81 |
Correct |
62 ms |
23812 KB |
Output is correct |
82 |
Correct |
267 ms |
47064 KB |
Output is correct |
83 |
Correct |
285 ms |
45000 KB |
Output is correct |
84 |
Correct |
280 ms |
45028 KB |
Output is correct |
85 |
Correct |
302 ms |
45012 KB |
Output is correct |
86 |
Correct |
293 ms |
47332 KB |
Output is correct |
87 |
Correct |
293 ms |
47312 KB |
Output is correct |