Submission #1098036

# Submission time Handle Problem Language Result Execution time Memory
1098036 2024-10-08T21:25:17 Z AndrijaM Network (BOI15_net) C++14
100 / 100
430 ms 49740 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int maxn=5e5+10;
const int mod=998244353;

vector<int>g[maxn];
vector<int>v;

void dfs(int node,int par)
{
    if(g[node].size()==1)
    {
        v.push_back(node);
        return ;
    }
    for(auto ax:g[node])
    {
        if(ax==par)continue;
        dfs(ax,node);
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ///freopen("lexicografic.in","r",stdin);
    ///freopen("lexicografic.out","w",stdout);
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        int a,b;
        cin>>a>>b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for(int i=0;i<n;i++)
    {
        if(g[i].size()!=1)
        {
            dfs(i,-1);
            break;
        }
    }
    vector<pair<int,int>>ans;
    int kol=v.size();
    kol/=2;
    for(int i=0;i<kol;i++)
    {
        ans.push_back({v[i],v[i+kol]});
    }
    if(v.size()%2==1)
    {
        ans.push_back({v[0],v[v.size()-1]});
    }
    cout<<ans.size()<<endl;
    for(auto ax:ans)
    {
        cout<<ax.first+1<<" "<<ax.second+1<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 12124 KB Output is correct
2 Correct 5 ms 12160 KB Output is correct
3 Correct 6 ms 12124 KB Output is correct
4 Correct 5 ms 12124 KB Output is correct
5 Correct 5 ms 12124 KB Output is correct
6 Correct 6 ms 12380 KB Output is correct
7 Correct 5 ms 12124 KB Output is correct
8 Correct 6 ms 12120 KB Output is correct
9 Correct 6 ms 12124 KB Output is correct
10 Correct 5 ms 12124 KB Output is correct
11 Correct 5 ms 12124 KB Output is correct
12 Correct 5 ms 11984 KB Output is correct
13 Correct 6 ms 12124 KB Output is correct
14 Correct 5 ms 12124 KB Output is correct
15 Correct 6 ms 12124 KB Output is correct
16 Correct 5 ms 12124 KB Output is correct
17 Correct 6 ms 12120 KB Output is correct
18 Correct 6 ms 12124 KB Output is correct
19 Correct 6 ms 12120 KB Output is correct
20 Correct 5 ms 12120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 12124 KB Output is correct
2 Correct 5 ms 12160 KB Output is correct
3 Correct 6 ms 12124 KB Output is correct
4 Correct 5 ms 12124 KB Output is correct
5 Correct 5 ms 12124 KB Output is correct
6 Correct 6 ms 12380 KB Output is correct
7 Correct 5 ms 12124 KB Output is correct
8 Correct 6 ms 12120 KB Output is correct
9 Correct 6 ms 12124 KB Output is correct
10 Correct 5 ms 12124 KB Output is correct
11 Correct 5 ms 12124 KB Output is correct
12 Correct 5 ms 11984 KB Output is correct
13 Correct 6 ms 12124 KB Output is correct
14 Correct 5 ms 12124 KB Output is correct
15 Correct 6 ms 12124 KB Output is correct
16 Correct 5 ms 12124 KB Output is correct
17 Correct 6 ms 12120 KB Output is correct
18 Correct 6 ms 12124 KB Output is correct
19 Correct 6 ms 12120 KB Output is correct
20 Correct 5 ms 12120 KB Output is correct
21 Correct 6 ms 12124 KB Output is correct
22 Correct 8 ms 12124 KB Output is correct
23 Correct 7 ms 12124 KB Output is correct
24 Correct 6 ms 12124 KB Output is correct
25 Correct 7 ms 12208 KB Output is correct
26 Correct 7 ms 12124 KB Output is correct
27 Correct 7 ms 12120 KB Output is correct
28 Correct 7 ms 12208 KB Output is correct
29 Correct 7 ms 12124 KB Output is correct
30 Correct 5 ms 12124 KB Output is correct
31 Correct 7 ms 12292 KB Output is correct
32 Correct 5 ms 12124 KB Output is correct
33 Correct 5 ms 12124 KB Output is correct
34 Correct 5 ms 12124 KB Output is correct
35 Correct 6 ms 12124 KB Output is correct
36 Correct 5 ms 12200 KB Output is correct
37 Correct 6 ms 12124 KB Output is correct
38 Correct 5 ms 12120 KB Output is correct
39 Correct 6 ms 12124 KB Output is correct
40 Correct 8 ms 12124 KB Output is correct
41 Correct 6 ms 12376 KB Output is correct
42 Correct 6 ms 12120 KB Output is correct
43 Correct 6 ms 12124 KB Output is correct
44 Correct 6 ms 12124 KB Output is correct
45 Correct 5 ms 12124 KB Output is correct
46 Correct 6 ms 12124 KB Output is correct
47 Correct 6 ms 12124 KB Output is correct
48 Correct 5 ms 12124 KB Output is correct
49 Correct 6 ms 12124 KB Output is correct
50 Correct 5 ms 12124 KB Output is correct
51 Correct 6 ms 12124 KB Output is correct
52 Correct 6 ms 12124 KB Output is correct
53 Correct 6 ms 12124 KB Output is correct
54 Correct 6 ms 12124 KB Output is correct
55 Correct 7 ms 12124 KB Output is correct
56 Correct 5 ms 12124 KB Output is correct
57 Correct 6 ms 12124 KB Output is correct
58 Correct 7 ms 12124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 12124 KB Output is correct
2 Correct 5 ms 12160 KB Output is correct
3 Correct 6 ms 12124 KB Output is correct
4 Correct 5 ms 12124 KB Output is correct
5 Correct 5 ms 12124 KB Output is correct
6 Correct 6 ms 12380 KB Output is correct
7 Correct 5 ms 12124 KB Output is correct
8 Correct 6 ms 12120 KB Output is correct
9 Correct 6 ms 12124 KB Output is correct
10 Correct 5 ms 12124 KB Output is correct
11 Correct 5 ms 12124 KB Output is correct
12 Correct 5 ms 11984 KB Output is correct
13 Correct 6 ms 12124 KB Output is correct
14 Correct 5 ms 12124 KB Output is correct
15 Correct 6 ms 12124 KB Output is correct
16 Correct 5 ms 12124 KB Output is correct
17 Correct 6 ms 12120 KB Output is correct
18 Correct 6 ms 12124 KB Output is correct
19 Correct 6 ms 12120 KB Output is correct
20 Correct 5 ms 12120 KB Output is correct
21 Correct 6 ms 12124 KB Output is correct
22 Correct 8 ms 12124 KB Output is correct
23 Correct 7 ms 12124 KB Output is correct
24 Correct 6 ms 12124 KB Output is correct
25 Correct 7 ms 12208 KB Output is correct
26 Correct 7 ms 12124 KB Output is correct
27 Correct 7 ms 12120 KB Output is correct
28 Correct 7 ms 12208 KB Output is correct
29 Correct 7 ms 12124 KB Output is correct
30 Correct 5 ms 12124 KB Output is correct
31 Correct 7 ms 12292 KB Output is correct
32 Correct 5 ms 12124 KB Output is correct
33 Correct 5 ms 12124 KB Output is correct
34 Correct 5 ms 12124 KB Output is correct
35 Correct 6 ms 12124 KB Output is correct
36 Correct 5 ms 12200 KB Output is correct
37 Correct 6 ms 12124 KB Output is correct
38 Correct 5 ms 12120 KB Output is correct
39 Correct 6 ms 12124 KB Output is correct
40 Correct 8 ms 12124 KB Output is correct
41 Correct 6 ms 12376 KB Output is correct
42 Correct 6 ms 12120 KB Output is correct
43 Correct 6 ms 12124 KB Output is correct
44 Correct 6 ms 12124 KB Output is correct
45 Correct 5 ms 12124 KB Output is correct
46 Correct 6 ms 12124 KB Output is correct
47 Correct 6 ms 12124 KB Output is correct
48 Correct 5 ms 12124 KB Output is correct
49 Correct 6 ms 12124 KB Output is correct
50 Correct 5 ms 12124 KB Output is correct
51 Correct 6 ms 12124 KB Output is correct
52 Correct 6 ms 12124 KB Output is correct
53 Correct 6 ms 12124 KB Output is correct
54 Correct 6 ms 12124 KB Output is correct
55 Correct 7 ms 12124 KB Output is correct
56 Correct 5 ms 12124 KB Output is correct
57 Correct 6 ms 12124 KB Output is correct
58 Correct 7 ms 12124 KB Output is correct
59 Correct 350 ms 44620 KB Output is correct
60 Correct 401 ms 47316 KB Output is correct
61 Correct 5 ms 12124 KB Output is correct
62 Correct 6 ms 12124 KB Output is correct
63 Correct 303 ms 40764 KB Output is correct
64 Correct 8 ms 12376 KB Output is correct
65 Correct 12 ms 13916 KB Output is correct
66 Correct 68 ms 27988 KB Output is correct
67 Correct 262 ms 46932 KB Output is correct
68 Correct 276 ms 48984 KB Output is correct
69 Correct 16 ms 13148 KB Output is correct
70 Correct 120 ms 24524 KB Output is correct
71 Correct 430 ms 49740 KB Output is correct
72 Correct 404 ms 47792 KB Output is correct
73 Correct 79 ms 20936 KB Output is correct
74 Correct 336 ms 43196 KB Output is correct
75 Correct 47 ms 16204 KB Output is correct
76 Correct 398 ms 49028 KB Output is correct
77 Correct 416 ms 49440 KB Output is correct
78 Correct 27 ms 15956 KB Output is correct
79 Correct 240 ms 45392 KB Output is correct
80 Correct 8 ms 12376 KB Output is correct
81 Correct 127 ms 23492 KB Output is correct
82 Correct 404 ms 46648 KB Output is correct
83 Correct 330 ms 43072 KB Output is correct
84 Correct 316 ms 43144 KB Output is correct
85 Correct 314 ms 43048 KB Output is correct
86 Correct 346 ms 47296 KB Output is correct
87 Correct 383 ms 47228 KB Output is correct