Submission #394663

# Submission time Handle Problem Language Result Execution time Memory
394663 2021-04-27T07:10:24 Z saniyar_krmi Network (BOI15_net) C++14
100 / 100
645 ms 64284 KB
// Possible Overdose for this coder
#include <bits/stdc++.h>
#define put(x) cerr << #x << ": " << x << '\n'
#define line() cerr << "**************\n"

//#define F first
//#define S second
//#define mul(x, y) (((x) * (y)) %mod)
//#define bit(i, j) (((i)>>(j)) &1)
//#define left(id) ((id<<1) + 1)
//#define right(id) ((id<<1) + 2)
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;

const int maxn = 5e5 + 10;
int n;
vector <int> G[maxn];
int l[maxn], num;

void dfs(int v, int par){
	if(G[v].size() == 1)
		l[v] = 1;

	for(int u: G[v]){
		if(u == par)
			continue;
		dfs(u, v);
		l[v] += l[u];
	}
}

int find(int v, int par){
	for(int u: G[v]){
		if(u == par)
			continue;
		if(l[u] > num / 2)
			return find(u, v);
	}
	return v;
}

vector <int> s[maxn];
void make(int v, int par, int x){
	if(G[v].size() == 1)
		s[x].push_back(v);

	for(int u: G[v]){
		if(u == par)
			continue;
		make(u, v, x);
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);  cout.tie(0);

	cin >> n;
	int u, v;
	for(int i=1; i<n; i++){
		cin >> u >> v;
		G[u].push_back(v), G[v].push_back(u);
	}

	dfs(1, 0);
	num = l[1];

	v = find(1, 0);

	int cnt = 0;
	for(int u: G[v])
		make(u, v, cnt++);

	int res = (num + 1) >> 1;
	vector <int> ans(2 * res);
	
	int pt = 0;
	for(int i=0; i<cnt; i++)
		for(int vi: s[i]){
			ans[pt] = vi;
			pt += 2;
			if(pt == (2 * res))
				pt = 1;
		}
	
	if(ans.size() && ans.back() == 0)
		ans.back() = s[0][0], put(1);

	cout << res << '\n';
	for(int i=0; i<ans.size(); i+=2)
		cout << ans[i] << ' ' << ans[i + 1] << '\n';
}

Compilation message

net.cpp: In function 'int main()':
net.cpp:94:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |  for(int i=0; i<ans.size(); i+=2)
      |               ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23756 KB Output is correct
2 Correct 15 ms 23692 KB Output is correct
3 Correct 17 ms 23756 KB Output is correct
4 Correct 16 ms 23748 KB Output is correct
5 Correct 15 ms 23804 KB Output is correct
6 Correct 16 ms 23756 KB Output is correct
7 Correct 15 ms 23792 KB Output is correct
8 Correct 15 ms 23756 KB Output is correct
9 Correct 15 ms 23756 KB Output is correct
10 Correct 16 ms 23800 KB Output is correct
11 Correct 15 ms 23756 KB Output is correct
12 Correct 16 ms 23752 KB Output is correct
13 Correct 15 ms 23756 KB Output is correct
14 Correct 16 ms 23712 KB Output is correct
15 Correct 16 ms 23756 KB Output is correct
16 Correct 15 ms 23736 KB Output is correct
17 Correct 16 ms 23716 KB Output is correct
18 Correct 15 ms 23756 KB Output is correct
19 Correct 15 ms 23808 KB Output is correct
20 Correct 15 ms 23684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23756 KB Output is correct
2 Correct 15 ms 23692 KB Output is correct
3 Correct 17 ms 23756 KB Output is correct
4 Correct 16 ms 23748 KB Output is correct
5 Correct 15 ms 23804 KB Output is correct
6 Correct 16 ms 23756 KB Output is correct
7 Correct 15 ms 23792 KB Output is correct
8 Correct 15 ms 23756 KB Output is correct
9 Correct 15 ms 23756 KB Output is correct
10 Correct 16 ms 23800 KB Output is correct
11 Correct 15 ms 23756 KB Output is correct
12 Correct 16 ms 23752 KB Output is correct
13 Correct 15 ms 23756 KB Output is correct
14 Correct 16 ms 23712 KB Output is correct
15 Correct 16 ms 23756 KB Output is correct
16 Correct 15 ms 23736 KB Output is correct
17 Correct 16 ms 23716 KB Output is correct
18 Correct 15 ms 23756 KB Output is correct
19 Correct 15 ms 23808 KB Output is correct
20 Correct 15 ms 23684 KB Output is correct
21 Correct 15 ms 23756 KB Output is correct
22 Correct 17 ms 24056 KB Output is correct
23 Correct 16 ms 23884 KB Output is correct
24 Correct 16 ms 23972 KB Output is correct
25 Correct 16 ms 23884 KB Output is correct
26 Correct 16 ms 23808 KB Output is correct
27 Correct 16 ms 23808 KB Output is correct
28 Correct 16 ms 23884 KB Output is correct
29 Correct 16 ms 23756 KB Output is correct
30 Correct 15 ms 23696 KB Output is correct
31 Correct 17 ms 23884 KB Output is correct
32 Correct 15 ms 23704 KB Output is correct
33 Correct 15 ms 23756 KB Output is correct
34 Correct 15 ms 23808 KB Output is correct
35 Correct 16 ms 23756 KB Output is correct
36 Correct 15 ms 23756 KB Output is correct
37 Correct 16 ms 23800 KB Output is correct
38 Correct 19 ms 23888 KB Output is correct
39 Correct 17 ms 23748 KB Output is correct
40 Correct 15 ms 23704 KB Output is correct
41 Correct 16 ms 23756 KB Output is correct
42 Correct 16 ms 23848 KB Output is correct
43 Correct 16 ms 23884 KB Output is correct
44 Correct 15 ms 23784 KB Output is correct
45 Correct 17 ms 23744 KB Output is correct
46 Correct 16 ms 23760 KB Output is correct
47 Correct 15 ms 23756 KB Output is correct
48 Correct 17 ms 23756 KB Output is correct
49 Correct 18 ms 23756 KB Output is correct
50 Correct 16 ms 23812 KB Output is correct
51 Correct 15 ms 23708 KB Output is correct
52 Correct 15 ms 23716 KB Output is correct
53 Correct 16 ms 23872 KB Output is correct
54 Correct 18 ms 23788 KB Output is correct
55 Correct 16 ms 23772 KB Output is correct
56 Correct 16 ms 23816 KB Output is correct
57 Correct 16 ms 23732 KB Output is correct
58 Correct 16 ms 23884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23756 KB Output is correct
2 Correct 15 ms 23692 KB Output is correct
3 Correct 17 ms 23756 KB Output is correct
4 Correct 16 ms 23748 KB Output is correct
5 Correct 15 ms 23804 KB Output is correct
6 Correct 16 ms 23756 KB Output is correct
7 Correct 15 ms 23792 KB Output is correct
8 Correct 15 ms 23756 KB Output is correct
9 Correct 15 ms 23756 KB Output is correct
10 Correct 16 ms 23800 KB Output is correct
11 Correct 15 ms 23756 KB Output is correct
12 Correct 16 ms 23752 KB Output is correct
13 Correct 15 ms 23756 KB Output is correct
14 Correct 16 ms 23712 KB Output is correct
15 Correct 16 ms 23756 KB Output is correct
16 Correct 15 ms 23736 KB Output is correct
17 Correct 16 ms 23716 KB Output is correct
18 Correct 15 ms 23756 KB Output is correct
19 Correct 15 ms 23808 KB Output is correct
20 Correct 15 ms 23684 KB Output is correct
21 Correct 15 ms 23756 KB Output is correct
22 Correct 17 ms 24056 KB Output is correct
23 Correct 16 ms 23884 KB Output is correct
24 Correct 16 ms 23972 KB Output is correct
25 Correct 16 ms 23884 KB Output is correct
26 Correct 16 ms 23808 KB Output is correct
27 Correct 16 ms 23808 KB Output is correct
28 Correct 16 ms 23884 KB Output is correct
29 Correct 16 ms 23756 KB Output is correct
30 Correct 15 ms 23696 KB Output is correct
31 Correct 17 ms 23884 KB Output is correct
32 Correct 15 ms 23704 KB Output is correct
33 Correct 15 ms 23756 KB Output is correct
34 Correct 15 ms 23808 KB Output is correct
35 Correct 16 ms 23756 KB Output is correct
36 Correct 15 ms 23756 KB Output is correct
37 Correct 16 ms 23800 KB Output is correct
38 Correct 19 ms 23888 KB Output is correct
39 Correct 17 ms 23748 KB Output is correct
40 Correct 15 ms 23704 KB Output is correct
41 Correct 16 ms 23756 KB Output is correct
42 Correct 16 ms 23848 KB Output is correct
43 Correct 16 ms 23884 KB Output is correct
44 Correct 15 ms 23784 KB Output is correct
45 Correct 17 ms 23744 KB Output is correct
46 Correct 16 ms 23760 KB Output is correct
47 Correct 15 ms 23756 KB Output is correct
48 Correct 17 ms 23756 KB Output is correct
49 Correct 18 ms 23756 KB Output is correct
50 Correct 16 ms 23812 KB Output is correct
51 Correct 15 ms 23708 KB Output is correct
52 Correct 15 ms 23716 KB Output is correct
53 Correct 16 ms 23872 KB Output is correct
54 Correct 18 ms 23788 KB Output is correct
55 Correct 16 ms 23772 KB Output is correct
56 Correct 16 ms 23816 KB Output is correct
57 Correct 16 ms 23732 KB Output is correct
58 Correct 16 ms 23884 KB Output is correct
59 Correct 472 ms 48148 KB Output is correct
60 Correct 511 ms 47392 KB Output is correct
61 Correct 16 ms 23756 KB Output is correct
62 Correct 15 ms 23760 KB Output is correct
63 Correct 395 ms 44808 KB Output is correct
64 Correct 18 ms 24268 KB Output is correct
65 Correct 28 ms 26076 KB Output is correct
66 Correct 199 ms 43376 KB Output is correct
67 Correct 621 ms 62416 KB Output is correct
68 Correct 619 ms 63416 KB Output is correct
69 Correct 23 ms 24928 KB Output is correct
70 Correct 113 ms 35828 KB Output is correct
71 Correct 409 ms 64284 KB Output is correct
72 Correct 413 ms 61948 KB Output is correct
73 Correct 108 ms 29936 KB Output is correct
74 Correct 566 ms 45812 KB Output is correct
75 Correct 42 ms 27336 KB Output is correct
76 Correct 392 ms 56836 KB Output is correct
77 Correct 373 ms 57452 KB Output is correct
78 Correct 48 ms 27208 KB Output is correct
79 Correct 645 ms 59456 KB Output is correct
80 Correct 17 ms 24012 KB Output is correct
81 Correct 136 ms 34216 KB Output is correct
82 Correct 485 ms 55116 KB Output is correct
83 Correct 542 ms 45812 KB Output is correct
84 Correct 522 ms 46028 KB Output is correct
85 Correct 549 ms 46156 KB Output is correct
86 Correct 525 ms 47140 KB Output is correct
87 Correct 535 ms 47360 KB Output is correct