Submission #436724

# Submission time Handle Problem Language Result Execution time Memory
436724 2021-06-24T19:48:19 Z ak2006 Network (BOI15_net) C++14
100 / 100
706 ms 51576 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void setIO()
{
    fast;
}
int n = 5e5 + 5,t;
vvi adj(n);
vi in(n),out(n),leaves;
void dfs(int u,int p)
{
    in[u] = ++t;
    for (int v:adj[u])if (v != p)
        dfs(v,u);
    out[u] = ++t;
    if (adj[u].size() == 1)leaves.pb(u);//leaves includes the root
}
bool cmp(int a,int b)
{
    return in[a] < in[b];
}
int main()
{
    setIO();
    cin>>n;
    for (int i = 0;i<n - 1;i++){int u,v;cin>>u>>v;adj[u].pb(v),adj[v].pb(u);}
    dfs(1,-1);
    sort(leaves.begin(),leaves.end(),cmp);
    int ans = (int)leaves.size();
    ans = (ans%2 == 1 ? ans/2 + 1 : ans/2);
    cout<<ans<<'\n';
    for (int i = 0;i<(int)leaves.size()/2;i++)
        cout<<leaves[i]<<" "<<leaves[(i + ans)%(int)leaves.size()]<<'\n';
    if ((int)leaves.size()%2 == 1)
        cout<<leaves[(int)leaves.size()/2]<<" "<<leaves[0];
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 15948 KB Output is correct
2 Correct 11 ms 15948 KB Output is correct
3 Correct 11 ms 15948 KB Output is correct
4 Correct 12 ms 15948 KB Output is correct
5 Correct 12 ms 15904 KB Output is correct
6 Correct 13 ms 15976 KB Output is correct
7 Correct 12 ms 15988 KB Output is correct
8 Correct 12 ms 15948 KB Output is correct
9 Correct 11 ms 15984 KB Output is correct
10 Correct 12 ms 15912 KB Output is correct
11 Correct 11 ms 15948 KB Output is correct
12 Correct 14 ms 15948 KB Output is correct
13 Correct 11 ms 15944 KB Output is correct
14 Correct 12 ms 15948 KB Output is correct
15 Correct 12 ms 15936 KB Output is correct
16 Correct 11 ms 15984 KB Output is correct
17 Correct 11 ms 15948 KB Output is correct
18 Correct 12 ms 15992 KB Output is correct
19 Correct 12 ms 15892 KB Output is correct
20 Correct 11 ms 15948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 15948 KB Output is correct
2 Correct 11 ms 15948 KB Output is correct
3 Correct 11 ms 15948 KB Output is correct
4 Correct 12 ms 15948 KB Output is correct
5 Correct 12 ms 15904 KB Output is correct
6 Correct 13 ms 15976 KB Output is correct
7 Correct 12 ms 15988 KB Output is correct
8 Correct 12 ms 15948 KB Output is correct
9 Correct 11 ms 15984 KB Output is correct
10 Correct 12 ms 15912 KB Output is correct
11 Correct 11 ms 15948 KB Output is correct
12 Correct 14 ms 15948 KB Output is correct
13 Correct 11 ms 15944 KB Output is correct
14 Correct 12 ms 15948 KB Output is correct
15 Correct 12 ms 15936 KB Output is correct
16 Correct 11 ms 15984 KB Output is correct
17 Correct 11 ms 15948 KB Output is correct
18 Correct 12 ms 15992 KB Output is correct
19 Correct 12 ms 15892 KB Output is correct
20 Correct 11 ms 15948 KB Output is correct
21 Correct 12 ms 15972 KB Output is correct
22 Correct 13 ms 16076 KB Output is correct
23 Correct 13 ms 15996 KB Output is correct
24 Correct 12 ms 16076 KB Output is correct
25 Correct 12 ms 16076 KB Output is correct
26 Correct 12 ms 15948 KB Output is correct
27 Correct 12 ms 15996 KB Output is correct
28 Correct 13 ms 15980 KB Output is correct
29 Correct 12 ms 15948 KB Output is correct
30 Correct 11 ms 15888 KB Output is correct
31 Correct 13 ms 15996 KB Output is correct
32 Correct 11 ms 15872 KB Output is correct
33 Correct 11 ms 15872 KB Output is correct
34 Correct 12 ms 15948 KB Output is correct
35 Correct 11 ms 15948 KB Output is correct
36 Correct 12 ms 15948 KB Output is correct
37 Correct 12 ms 15948 KB Output is correct
38 Correct 12 ms 16036 KB Output is correct
39 Correct 12 ms 15948 KB Output is correct
40 Correct 11 ms 15948 KB Output is correct
41 Correct 12 ms 15892 KB Output is correct
42 Correct 11 ms 15908 KB Output is correct
43 Correct 11 ms 16044 KB Output is correct
44 Correct 12 ms 15948 KB Output is correct
45 Correct 11 ms 15948 KB Output is correct
46 Correct 11 ms 15984 KB Output is correct
47 Correct 11 ms 15980 KB Output is correct
48 Correct 12 ms 15992 KB Output is correct
49 Correct 11 ms 15972 KB Output is correct
50 Correct 12 ms 15912 KB Output is correct
51 Correct 11 ms 15948 KB Output is correct
52 Correct 12 ms 15948 KB Output is correct
53 Correct 12 ms 16040 KB Output is correct
54 Correct 12 ms 15948 KB Output is correct
55 Correct 12 ms 15948 KB Output is correct
56 Correct 12 ms 15892 KB Output is correct
57 Correct 11 ms 15948 KB Output is correct
58 Correct 13 ms 16076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 15948 KB Output is correct
2 Correct 11 ms 15948 KB Output is correct
3 Correct 11 ms 15948 KB Output is correct
4 Correct 12 ms 15948 KB Output is correct
5 Correct 12 ms 15904 KB Output is correct
6 Correct 13 ms 15976 KB Output is correct
7 Correct 12 ms 15988 KB Output is correct
8 Correct 12 ms 15948 KB Output is correct
9 Correct 11 ms 15984 KB Output is correct
10 Correct 12 ms 15912 KB Output is correct
11 Correct 11 ms 15948 KB Output is correct
12 Correct 14 ms 15948 KB Output is correct
13 Correct 11 ms 15944 KB Output is correct
14 Correct 12 ms 15948 KB Output is correct
15 Correct 12 ms 15936 KB Output is correct
16 Correct 11 ms 15984 KB Output is correct
17 Correct 11 ms 15948 KB Output is correct
18 Correct 12 ms 15992 KB Output is correct
19 Correct 12 ms 15892 KB Output is correct
20 Correct 11 ms 15948 KB Output is correct
21 Correct 12 ms 15972 KB Output is correct
22 Correct 13 ms 16076 KB Output is correct
23 Correct 13 ms 15996 KB Output is correct
24 Correct 12 ms 16076 KB Output is correct
25 Correct 12 ms 16076 KB Output is correct
26 Correct 12 ms 15948 KB Output is correct
27 Correct 12 ms 15996 KB Output is correct
28 Correct 13 ms 15980 KB Output is correct
29 Correct 12 ms 15948 KB Output is correct
30 Correct 11 ms 15888 KB Output is correct
31 Correct 13 ms 15996 KB Output is correct
32 Correct 11 ms 15872 KB Output is correct
33 Correct 11 ms 15872 KB Output is correct
34 Correct 12 ms 15948 KB Output is correct
35 Correct 11 ms 15948 KB Output is correct
36 Correct 12 ms 15948 KB Output is correct
37 Correct 12 ms 15948 KB Output is correct
38 Correct 12 ms 16036 KB Output is correct
39 Correct 12 ms 15948 KB Output is correct
40 Correct 11 ms 15948 KB Output is correct
41 Correct 12 ms 15892 KB Output is correct
42 Correct 11 ms 15908 KB Output is correct
43 Correct 11 ms 16044 KB Output is correct
44 Correct 12 ms 15948 KB Output is correct
45 Correct 11 ms 15948 KB Output is correct
46 Correct 11 ms 15984 KB Output is correct
47 Correct 11 ms 15980 KB Output is correct
48 Correct 12 ms 15992 KB Output is correct
49 Correct 11 ms 15972 KB Output is correct
50 Correct 12 ms 15912 KB Output is correct
51 Correct 11 ms 15948 KB Output is correct
52 Correct 12 ms 15948 KB Output is correct
53 Correct 12 ms 16040 KB Output is correct
54 Correct 12 ms 15948 KB Output is correct
55 Correct 12 ms 15948 KB Output is correct
56 Correct 12 ms 15892 KB Output is correct
57 Correct 11 ms 15948 KB Output is correct
58 Correct 13 ms 16076 KB Output is correct
59 Correct 591 ms 39980 KB Output is correct
60 Correct 671 ms 42660 KB Output is correct
61 Correct 11 ms 15948 KB Output is correct
62 Correct 12 ms 15900 KB Output is correct
63 Correct 523 ms 37420 KB Output is correct
64 Correct 14 ms 16332 KB Output is correct
65 Correct 23 ms 17728 KB Output is correct
66 Correct 170 ms 31752 KB Output is correct
67 Correct 615 ms 50940 KB Output is correct
68 Correct 587 ms 51576 KB Output is correct
69 Correct 20 ms 16844 KB Output is correct
70 Correct 155 ms 25068 KB Output is correct
71 Correct 569 ms 45748 KB Output is correct
72 Correct 596 ms 44508 KB Output is correct
73 Correct 128 ms 22976 KB Output is correct
74 Correct 641 ms 41520 KB Output is correct
75 Correct 47 ms 19140 KB Output is correct
76 Correct 581 ms 45440 KB Output is correct
77 Correct 598 ms 45520 KB Output is correct
78 Correct 40 ms 19268 KB Output is correct
79 Correct 619 ms 49156 KB Output is correct
80 Correct 13 ms 16280 KB Output is correct
81 Correct 197 ms 25180 KB Output is correct
82 Correct 547 ms 43452 KB Output is correct
83 Correct 663 ms 41528 KB Output is correct
84 Correct 654 ms 41556 KB Output is correct
85 Correct 600 ms 41644 KB Output is correct
86 Correct 698 ms 42680 KB Output is correct
87 Correct 706 ms 42720 KB Output is correct