답안 #824330

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
824330 2023-08-14T02:44:30 Z irmuun Network (BOI15_net) C++17
100 / 100
359 ms 70976 KB
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n;
    cin>>n;
    vector<ll>adj[n+1];
    for(ll i=1;i<n;i++){
        ll a,b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    ll mx=0,ind;
    for(ll i=1;i<=n;i++){
        if(adj[i].size()>mx){
            mx=adj[i].size();
            ind=i;
        }
    }
    vector<ll>ord;
    function <void(ll,ll)> dfs=[&](ll x,ll p){
        if(adj[x].size()==1){
            ord.pb(x);
        }
        for(auto y:adj[x]){
            if(y!=p){
                dfs(y,x);
            }
        }
    };
    for(auto x:adj[ind]){
        dfs(x,ind);
    }
    if(ord.size()%2==1){
        ord.pb(ord[0]);
    }
    ll sz=ord.size();
    cout<<sz/2<<"\n";
    for(ll i=0;i<sz/2;i++){
        cout<<ord[i]<<' '<<ord[i+sz/2]<<"\n";
    }
}

Compilation message

net.cpp: In function 'int main()':
net.cpp:25:25: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   25 |         if(adj[i].size()>mx){
      |            ~~~~~~~~~~~~~^~~
net.cpp:23:13: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
   23 |     ll mx=0,ind;
      |             ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 276 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 276 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 456 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 316 KB Output is correct
37 Correct 1 ms 320 KB Output is correct
38 Correct 1 ms 324 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 320 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 320 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 276 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 456 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 316 KB Output is correct
37 Correct 1 ms 320 KB Output is correct
38 Correct 1 ms 324 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 320 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 320 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 460 KB Output is correct
59 Correct 262 ms 39452 KB Output is correct
60 Correct 307 ms 43444 KB Output is correct
61 Correct 0 ms 212 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 254 ms 34316 KB Output is correct
64 Correct 2 ms 852 KB Output is correct
65 Correct 7 ms 2892 KB Output is correct
66 Correct 67 ms 20740 KB Output is correct
67 Correct 344 ms 55372 KB Output is correct
68 Correct 359 ms 70976 KB Output is correct
69 Correct 4 ms 1620 KB Output is correct
70 Correct 48 ms 15248 KB Output is correct
71 Correct 193 ms 45712 KB Output is correct
72 Correct 227 ms 44256 KB Output is correct
73 Correct 47 ms 11580 KB Output is correct
74 Correct 297 ms 41248 KB Output is correct
75 Correct 15 ms 5156 KB Output is correct
76 Correct 262 ms 45284 KB Output is correct
77 Correct 200 ms 45572 KB Output is correct
78 Correct 17 ms 6228 KB Output is correct
79 Correct 321 ms 47368 KB Output is correct
80 Correct 1 ms 596 KB Output is correct
81 Correct 60 ms 14764 KB Output is correct
82 Correct 262 ms 43160 KB Output is correct
83 Correct 301 ms 41120 KB Output is correct
84 Correct 334 ms 41168 KB Output is correct
85 Correct 331 ms 41172 KB Output is correct
86 Correct 320 ms 43372 KB Output is correct
87 Correct 311 ms 43352 KB Output is correct