Submission #480594

# Submission time Handle Problem Language Result Execution time Memory
480594 2021-10-17T08:15:19 Z Sohsoh84 Network (BOI15_net) C++17
100 / 100
494 ms 61484 KB
//: // ////: ///  / : //// / :
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pll;

#define all(x)			(x).begin(),(x).end()
#define X			first
#define Y			second
#define sep			' '
#define endl			'\n'
#define debug(x)		cerr << #x << ": " <<  x << endl;

const ll MAXN = 1e6 + 10;

int n, tin[MAXN], t;
vector<int> adj[MAXN], L;
vector<pll> ans;

void dfs(int v, int p) {
	tin[v] = ++t;
	if (adj[v].size() == 1)
		L.push_back(v);

	for (int u : adj[v])
		if (u != p)
			dfs(u, v);
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	for (int i = 1; i <= n; i++) {
		if (adj[i].size() > 1) {
			dfs(i, 0);
			break;
		}
	}

	sort(all(L), [] (int a, int b) {
		return tin[a] < tin[b];	
	});

	for (int i = 0; i < L.size() / 2; i++)
		ans.push_back({L[i], L[i + L.size() / 2]});

	if (L.size() & 1) ans.push_back({L.back(), L.front()});
	
	cout << ans.size() << endl;
	for (pll e : ans) cout << e.X << sep << e.Y << endl;
	return 0;
}

Compilation message

net.cpp: In function 'int main()':
net.cpp:54:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |  for (int i = 0; i < L.size() / 2; i++)
      |                  ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 12 ms 23800 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23808 KB Output is correct
5 Correct 14 ms 23800 KB Output is correct
6 Correct 12 ms 23756 KB Output is correct
7 Correct 14 ms 23716 KB Output is correct
8 Correct 13 ms 23736 KB Output is correct
9 Correct 14 ms 23756 KB Output is correct
10 Correct 14 ms 23808 KB Output is correct
11 Correct 13 ms 23756 KB Output is correct
12 Correct 14 ms 23756 KB Output is correct
13 Correct 14 ms 23756 KB Output is correct
14 Correct 13 ms 23756 KB Output is correct
15 Correct 13 ms 23756 KB Output is correct
16 Correct 15 ms 23780 KB Output is correct
17 Correct 15 ms 23756 KB Output is correct
18 Correct 14 ms 23756 KB Output is correct
19 Correct 15 ms 23808 KB Output is correct
20 Correct 15 ms 23892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 12 ms 23800 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23808 KB Output is correct
5 Correct 14 ms 23800 KB Output is correct
6 Correct 12 ms 23756 KB Output is correct
7 Correct 14 ms 23716 KB Output is correct
8 Correct 13 ms 23736 KB Output is correct
9 Correct 14 ms 23756 KB Output is correct
10 Correct 14 ms 23808 KB Output is correct
11 Correct 13 ms 23756 KB Output is correct
12 Correct 14 ms 23756 KB Output is correct
13 Correct 14 ms 23756 KB Output is correct
14 Correct 13 ms 23756 KB Output is correct
15 Correct 13 ms 23756 KB Output is correct
16 Correct 15 ms 23780 KB Output is correct
17 Correct 15 ms 23756 KB Output is correct
18 Correct 14 ms 23756 KB Output is correct
19 Correct 15 ms 23808 KB Output is correct
20 Correct 15 ms 23892 KB Output is correct
21 Correct 16 ms 23756 KB Output is correct
22 Correct 18 ms 23924 KB Output is correct
23 Correct 15 ms 23884 KB Output is correct
24 Correct 15 ms 23980 KB Output is correct
25 Correct 15 ms 23884 KB Output is correct
26 Correct 14 ms 23884 KB Output is correct
27 Correct 15 ms 23884 KB Output is correct
28 Correct 15 ms 23848 KB Output is correct
29 Correct 15 ms 23856 KB Output is correct
30 Correct 15 ms 23808 KB Output is correct
31 Correct 16 ms 23884 KB Output is correct
32 Correct 13 ms 23756 KB Output is correct
33 Correct 16 ms 23760 KB Output is correct
34 Correct 15 ms 23756 KB Output is correct
35 Correct 13 ms 23804 KB Output is correct
36 Correct 14 ms 23776 KB Output is correct
37 Correct 13 ms 23724 KB Output is correct
38 Correct 13 ms 23756 KB Output is correct
39 Correct 13 ms 23800 KB Output is correct
40 Correct 17 ms 23756 KB Output is correct
41 Correct 17 ms 23756 KB Output is correct
42 Correct 15 ms 23756 KB Output is correct
43 Correct 16 ms 23812 KB Output is correct
44 Correct 13 ms 23756 KB Output is correct
45 Correct 14 ms 23808 KB Output is correct
46 Correct 14 ms 23756 KB Output is correct
47 Correct 13 ms 23768 KB Output is correct
48 Correct 13 ms 23800 KB Output is correct
49 Correct 15 ms 23852 KB Output is correct
50 Correct 16 ms 23804 KB Output is correct
51 Correct 13 ms 23756 KB Output is correct
52 Correct 13 ms 23756 KB Output is correct
53 Correct 14 ms 23756 KB Output is correct
54 Correct 14 ms 23804 KB Output is correct
55 Correct 14 ms 23860 KB Output is correct
56 Correct 13 ms 23800 KB Output is correct
57 Correct 15 ms 23728 KB Output is correct
58 Correct 16 ms 23944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 12 ms 23800 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23808 KB Output is correct
5 Correct 14 ms 23800 KB Output is correct
6 Correct 12 ms 23756 KB Output is correct
7 Correct 14 ms 23716 KB Output is correct
8 Correct 13 ms 23736 KB Output is correct
9 Correct 14 ms 23756 KB Output is correct
10 Correct 14 ms 23808 KB Output is correct
11 Correct 13 ms 23756 KB Output is correct
12 Correct 14 ms 23756 KB Output is correct
13 Correct 14 ms 23756 KB Output is correct
14 Correct 13 ms 23756 KB Output is correct
15 Correct 13 ms 23756 KB Output is correct
16 Correct 15 ms 23780 KB Output is correct
17 Correct 15 ms 23756 KB Output is correct
18 Correct 14 ms 23756 KB Output is correct
19 Correct 15 ms 23808 KB Output is correct
20 Correct 15 ms 23892 KB Output is correct
21 Correct 16 ms 23756 KB Output is correct
22 Correct 18 ms 23924 KB Output is correct
23 Correct 15 ms 23884 KB Output is correct
24 Correct 15 ms 23980 KB Output is correct
25 Correct 15 ms 23884 KB Output is correct
26 Correct 14 ms 23884 KB Output is correct
27 Correct 15 ms 23884 KB Output is correct
28 Correct 15 ms 23848 KB Output is correct
29 Correct 15 ms 23856 KB Output is correct
30 Correct 15 ms 23808 KB Output is correct
31 Correct 16 ms 23884 KB Output is correct
32 Correct 13 ms 23756 KB Output is correct
33 Correct 16 ms 23760 KB Output is correct
34 Correct 15 ms 23756 KB Output is correct
35 Correct 13 ms 23804 KB Output is correct
36 Correct 14 ms 23776 KB Output is correct
37 Correct 13 ms 23724 KB Output is correct
38 Correct 13 ms 23756 KB Output is correct
39 Correct 13 ms 23800 KB Output is correct
40 Correct 17 ms 23756 KB Output is correct
41 Correct 17 ms 23756 KB Output is correct
42 Correct 15 ms 23756 KB Output is correct
43 Correct 16 ms 23812 KB Output is correct
44 Correct 13 ms 23756 KB Output is correct
45 Correct 14 ms 23808 KB Output is correct
46 Correct 14 ms 23756 KB Output is correct
47 Correct 13 ms 23768 KB Output is correct
48 Correct 13 ms 23800 KB Output is correct
49 Correct 15 ms 23852 KB Output is correct
50 Correct 16 ms 23804 KB Output is correct
51 Correct 13 ms 23756 KB Output is correct
52 Correct 13 ms 23756 KB Output is correct
53 Correct 14 ms 23756 KB Output is correct
54 Correct 14 ms 23804 KB Output is correct
55 Correct 14 ms 23860 KB Output is correct
56 Correct 13 ms 23800 KB Output is correct
57 Correct 15 ms 23728 KB Output is correct
58 Correct 16 ms 23944 KB Output is correct
59 Correct 366 ms 50648 KB Output is correct
60 Correct 442 ms 53664 KB Output is correct
61 Correct 14 ms 23756 KB Output is correct
62 Correct 12 ms 23756 KB Output is correct
63 Correct 323 ms 47976 KB Output is correct
64 Correct 15 ms 24140 KB Output is correct
65 Correct 24 ms 25788 KB Output is correct
66 Correct 138 ms 40260 KB Output is correct
67 Correct 460 ms 60600 KB Output is correct
68 Correct 494 ms 61484 KB Output is correct
69 Correct 18 ms 24780 KB Output is correct
70 Correct 126 ms 34092 KB Output is correct
71 Correct 339 ms 57548 KB Output is correct
72 Correct 342 ms 56108 KB Output is correct
73 Correct 95 ms 31560 KB Output is correct
74 Correct 480 ms 52388 KB Output is correct
75 Correct 36 ms 27440 KB Output is correct
76 Correct 313 ms 57136 KB Output is correct
77 Correct 308 ms 57208 KB Output is correct
78 Correct 40 ms 27460 KB Output is correct
79 Correct 449 ms 58752 KB Output is correct
80 Correct 14 ms 24012 KB Output is correct
81 Correct 112 ms 34152 KB Output is correct
82 Correct 421 ms 54620 KB Output is correct
83 Correct 455 ms 52352 KB Output is correct
84 Correct 446 ms 52264 KB Output is correct
85 Correct 420 ms 52268 KB Output is correct
86 Correct 423 ms 53764 KB Output is correct
87 Correct 431 ms 53808 KB Output is correct