답안 #765401

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
765401 2023-06-24T12:19:31 Z vjudge1 Network (BOI15_net) C++17
100 / 100
998 ms 84680 KB
/******************
tree-bends-in-youth
//24///06///2023///
******************/
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
const ll N = 1e6 + 1;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;
vector<int>g[N];
vector <int> l;
map<int,int>used;
int tm;
void dfs(int v){
    used[v]=1;
    if(g[v].size() == 1)l.pb(v);
    for(ll to : g[v]){
        if(!used[to]){
            dfs(to);
        }
    }
}
void solve(){
    int n;
    cin >> n;
    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        g[x].pb(y);
        g[y].pb(x);
    }
    int r = 0;
    for(int i = 1;i <= n;i++){
        if(g[i].size() > 1){
            r = i;
            break;
        }
    }
    dfs(r);
    int k = (l.size() + 1) / 2;
    cout << k << '\n';
    for(int i = 0;i + k < l.size();i++){
        cout << l[i] << " " << l[i + k] << '\n';
    }
    if(l.size() % 2){
        cout << l[0] << " " << l[k - 1] << '\n';
    }
}
main () {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	//freopen("censor.in","r",stdin);
	//freopen("censor.out","w",stdout);
    ll T = 1;
    //cin >> T;
    for(ll i = 1;i <= T;i++){
      //  cout << "Case " << i << ":\n";
        solve();
    }
}

Compilation message

net.cpp: In function 'void solve()':
net.cpp:47:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for(int i = 0;i + k < l.size();i++){
      |                   ~~~~~~^~~~~~~~~~
net.cpp: At global scope:
net.cpp:54:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   54 | main () {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 11 ms 23768 KB Output is correct
3 Correct 11 ms 23720 KB Output is correct
4 Correct 11 ms 23764 KB Output is correct
5 Correct 12 ms 23808 KB Output is correct
6 Correct 11 ms 23784 KB Output is correct
7 Correct 14 ms 23764 KB Output is correct
8 Correct 13 ms 23808 KB Output is correct
9 Correct 11 ms 23764 KB Output is correct
10 Correct 13 ms 23804 KB Output is correct
11 Correct 12 ms 23680 KB Output is correct
12 Correct 11 ms 23764 KB Output is correct
13 Correct 11 ms 23764 KB Output is correct
14 Correct 12 ms 23776 KB Output is correct
15 Correct 12 ms 23764 KB Output is correct
16 Correct 12 ms 23740 KB Output is correct
17 Correct 12 ms 23764 KB Output is correct
18 Correct 12 ms 23804 KB Output is correct
19 Correct 11 ms 23784 KB Output is correct
20 Correct 12 ms 23736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 11 ms 23768 KB Output is correct
3 Correct 11 ms 23720 KB Output is correct
4 Correct 11 ms 23764 KB Output is correct
5 Correct 12 ms 23808 KB Output is correct
6 Correct 11 ms 23784 KB Output is correct
7 Correct 14 ms 23764 KB Output is correct
8 Correct 13 ms 23808 KB Output is correct
9 Correct 11 ms 23764 KB Output is correct
10 Correct 13 ms 23804 KB Output is correct
11 Correct 12 ms 23680 KB Output is correct
12 Correct 11 ms 23764 KB Output is correct
13 Correct 11 ms 23764 KB Output is correct
14 Correct 12 ms 23776 KB Output is correct
15 Correct 12 ms 23764 KB Output is correct
16 Correct 12 ms 23740 KB Output is correct
17 Correct 12 ms 23764 KB Output is correct
18 Correct 12 ms 23804 KB Output is correct
19 Correct 11 ms 23784 KB Output is correct
20 Correct 12 ms 23736 KB Output is correct
21 Correct 11 ms 23764 KB Output is correct
22 Correct 12 ms 23984 KB Output is correct
23 Correct 12 ms 23892 KB Output is correct
24 Correct 12 ms 23892 KB Output is correct
25 Correct 12 ms 23892 KB Output is correct
26 Correct 13 ms 23888 KB Output is correct
27 Correct 12 ms 23968 KB Output is correct
28 Correct 13 ms 23976 KB Output is correct
29 Correct 13 ms 23892 KB Output is correct
30 Correct 11 ms 23764 KB Output is correct
31 Correct 12 ms 23892 KB Output is correct
32 Correct 12 ms 23804 KB Output is correct
33 Correct 11 ms 23764 KB Output is correct
34 Correct 12 ms 23764 KB Output is correct
35 Correct 11 ms 23792 KB Output is correct
36 Correct 11 ms 23704 KB Output is correct
37 Correct 12 ms 23764 KB Output is correct
38 Correct 12 ms 23844 KB Output is correct
39 Correct 11 ms 23764 KB Output is correct
40 Correct 11 ms 23752 KB Output is correct
41 Correct 11 ms 23764 KB Output is correct
42 Correct 12 ms 23728 KB Output is correct
43 Correct 11 ms 23804 KB Output is correct
44 Correct 14 ms 23804 KB Output is correct
45 Correct 12 ms 23764 KB Output is correct
46 Correct 12 ms 23892 KB Output is correct
47 Correct 11 ms 23700 KB Output is correct
48 Correct 12 ms 23836 KB Output is correct
49 Correct 15 ms 23892 KB Output is correct
50 Correct 15 ms 23724 KB Output is correct
51 Correct 11 ms 23740 KB Output is correct
52 Correct 11 ms 23816 KB Output is correct
53 Correct 13 ms 23840 KB Output is correct
54 Correct 11 ms 23764 KB Output is correct
55 Correct 11 ms 23832 KB Output is correct
56 Correct 10 ms 23720 KB Output is correct
57 Correct 11 ms 23856 KB Output is correct
58 Correct 11 ms 23888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 11 ms 23768 KB Output is correct
3 Correct 11 ms 23720 KB Output is correct
4 Correct 11 ms 23764 KB Output is correct
5 Correct 12 ms 23808 KB Output is correct
6 Correct 11 ms 23784 KB Output is correct
7 Correct 14 ms 23764 KB Output is correct
8 Correct 13 ms 23808 KB Output is correct
9 Correct 11 ms 23764 KB Output is correct
10 Correct 13 ms 23804 KB Output is correct
11 Correct 12 ms 23680 KB Output is correct
12 Correct 11 ms 23764 KB Output is correct
13 Correct 11 ms 23764 KB Output is correct
14 Correct 12 ms 23776 KB Output is correct
15 Correct 12 ms 23764 KB Output is correct
16 Correct 12 ms 23740 KB Output is correct
17 Correct 12 ms 23764 KB Output is correct
18 Correct 12 ms 23804 KB Output is correct
19 Correct 11 ms 23784 KB Output is correct
20 Correct 12 ms 23736 KB Output is correct
21 Correct 11 ms 23764 KB Output is correct
22 Correct 12 ms 23984 KB Output is correct
23 Correct 12 ms 23892 KB Output is correct
24 Correct 12 ms 23892 KB Output is correct
25 Correct 12 ms 23892 KB Output is correct
26 Correct 13 ms 23888 KB Output is correct
27 Correct 12 ms 23968 KB Output is correct
28 Correct 13 ms 23976 KB Output is correct
29 Correct 13 ms 23892 KB Output is correct
30 Correct 11 ms 23764 KB Output is correct
31 Correct 12 ms 23892 KB Output is correct
32 Correct 12 ms 23804 KB Output is correct
33 Correct 11 ms 23764 KB Output is correct
34 Correct 12 ms 23764 KB Output is correct
35 Correct 11 ms 23792 KB Output is correct
36 Correct 11 ms 23704 KB Output is correct
37 Correct 12 ms 23764 KB Output is correct
38 Correct 12 ms 23844 KB Output is correct
39 Correct 11 ms 23764 KB Output is correct
40 Correct 11 ms 23752 KB Output is correct
41 Correct 11 ms 23764 KB Output is correct
42 Correct 12 ms 23728 KB Output is correct
43 Correct 11 ms 23804 KB Output is correct
44 Correct 14 ms 23804 KB Output is correct
45 Correct 12 ms 23764 KB Output is correct
46 Correct 12 ms 23892 KB Output is correct
47 Correct 11 ms 23700 KB Output is correct
48 Correct 12 ms 23836 KB Output is correct
49 Correct 15 ms 23892 KB Output is correct
50 Correct 15 ms 23724 KB Output is correct
51 Correct 11 ms 23740 KB Output is correct
52 Correct 11 ms 23816 KB Output is correct
53 Correct 13 ms 23840 KB Output is correct
54 Correct 11 ms 23764 KB Output is correct
55 Correct 11 ms 23832 KB Output is correct
56 Correct 10 ms 23720 KB Output is correct
57 Correct 11 ms 23856 KB Output is correct
58 Correct 11 ms 23888 KB Output is correct
59 Correct 636 ms 62972 KB Output is correct
60 Correct 739 ms 67152 KB Output is correct
61 Correct 11 ms 23804 KB Output is correct
62 Correct 12 ms 23720 KB Output is correct
63 Correct 644 ms 58596 KB Output is correct
64 Correct 17 ms 24548 KB Output is correct
65 Correct 29 ms 27128 KB Output is correct
66 Correct 243 ms 51172 KB Output is correct
67 Correct 986 ms 83868 KB Output is correct
68 Correct 998 ms 84680 KB Output is correct
69 Correct 27 ms 25164 KB Output is correct
70 Correct 146 ms 38280 KB Output is correct
71 Correct 654 ms 70248 KB Output is correct
72 Correct 693 ms 69532 KB Output is correct
73 Correct 149 ms 35436 KB Output is correct
74 Correct 868 ms 66180 KB Output is correct
75 Correct 51 ms 28856 KB Output is correct
76 Correct 631 ms 69904 KB Output is correct
77 Correct 617 ms 70320 KB Output is correct
78 Correct 52 ms 29772 KB Output is correct
79 Correct 895 ms 80992 KB Output is correct
80 Correct 14 ms 24148 KB Output is correct
81 Correct 158 ms 38740 KB Output is correct
82 Correct 672 ms 68220 KB Output is correct
83 Correct 760 ms 66068 KB Output is correct
84 Correct 736 ms 66152 KB Output is correct
85 Correct 752 ms 66268 KB Output is correct
86 Correct 780 ms 67172 KB Output is correct
87 Correct 718 ms 67232 KB Output is correct