Submission #292799

# Submission time Handle Problem Language Result Execution time Memory
292799 2020-09-07T13:34:46 Z 임성재(#5807) ROI16_sending (ROI16_sending) C++17
56 / 100
5000 ms 31856 KB
#include<bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define em emplace 
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;

int n, k;
vector<int> g[200010];
vector<int> v;
int d[200010];
int num[200010];
int a[200010];
int b[200010];
int sp[400010][21];
int tb[400010];

int dist(int a, int b) {
	if(num[a] > num[b]) swap(a, b);

	int ret = d[a] + d[b];

	int x = tb[num[b] - num[a] + 1];
	ret -= 2 * min(sp[num[a]][x], sp[num[b] - (1<<x) + 1][x]);
 	
 	return ret;
}

void dfs(int x) {
	num[x] = v.size();
	v.eb(d[x]);

	for(auto i : g[x]) {
		d[i] = d[x] + 1;
		dfs(i);

		v.eb(d[x]);
	}
}

int main() {
	fast;

	cin >> n >> k;

	for(int i=2; i<=n; i++) {
		int p;
		cin >> p;

		g[p].eb(i);
	}

	dfs(1);

	for(int i=0; i<v.size(); i++) sp[i][0] = v[i];

	for(int i=1; i<=20; i++) {
		for(int j=0; j<v.size(); j++) {
			sp[j][i] = min(sp[j][i-1], sp[min(j + (1 << i-1), (int) v.size()-1)][i-1]);
		}
	}

	for(int i=2; i<v.size(); i++) {
		tb[i] = tb[i/2] + 1;
	}

	for(int i=1; i<=k; i++) {
		cin >> a[i] >> b[i];
	}

	int ans = 0;
	pii mxi = mp(1, 2);

	for(int i=1; i<=k; i++) {
		for(int j = i+1; j<=k; j++) {
			int x = dist(a[i], b[i]) + dist(a[j], b[j]);
			x -= min(dist(a[i], a[j]) + dist(b[i], b[j]), dist(a[i], b[j]) + dist(a[j], b[i]));
			
			if(x > ans) {
				ans = x;
				mxi = mp(i, j);
			}
		}
	}

	cout << ans / 2 << "\n";
	cout << mxi.fi << " " << mxi.se;
}

Compilation message

sending.cpp: In function 'int main()':
sending.cpp:65:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |  for(int i=0; i<v.size(); i++) sp[i][0] = v[i];
      |               ~^~~~~~~~~
sending.cpp:68:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   for(int j=0; j<v.size(); j++) {
      |                ~^~~~~~~~~
sending.cpp:69:49: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   69 |    sp[j][i] = min(sp[j][i-1], sp[min(j + (1 << i-1), (int) v.size()-1)][i-1]);
      |                                                ~^~
sending.cpp:73:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |  for(int i=2; i<v.size(); i++) {
      |               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 5024 KB Output is correct
6 Correct 4 ms 5120 KB Output is correct
7 Correct 4 ms 5120 KB Output is correct
8 Correct 4 ms 5120 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 4 ms 5120 KB Output is correct
11 Correct 4 ms 5120 KB Output is correct
12 Correct 4 ms 5120 KB Output is correct
13 Correct 4 ms 5120 KB Output is correct
14 Correct 4 ms 5120 KB Output is correct
15 Correct 4 ms 5120 KB Output is correct
16 Correct 3 ms 5120 KB Output is correct
17 Correct 4 ms 5120 KB Output is correct
18 Correct 4 ms 5120 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 5024 KB Output is correct
6 Correct 4 ms 5120 KB Output is correct
7 Correct 4 ms 5120 KB Output is correct
8 Correct 4 ms 5120 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 4 ms 5120 KB Output is correct
11 Correct 4 ms 5120 KB Output is correct
12 Correct 4 ms 5120 KB Output is correct
13 Correct 4 ms 5120 KB Output is correct
14 Correct 4 ms 5120 KB Output is correct
15 Correct 4 ms 5120 KB Output is correct
16 Correct 3 ms 5120 KB Output is correct
17 Correct 4 ms 5120 KB Output is correct
18 Correct 4 ms 5120 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 31 ms 5888 KB Output is correct
21 Correct 32 ms 5888 KB Output is correct
22 Correct 30 ms 6144 KB Output is correct
23 Correct 31 ms 6120 KB Output is correct
24 Correct 31 ms 6060 KB Output is correct
25 Correct 36 ms 5928 KB Output is correct
26 Correct 30 ms 6144 KB Output is correct
27 Correct 31 ms 5888 KB Output is correct
28 Correct 36 ms 5888 KB Output is correct
29 Correct 22 ms 6144 KB Output is correct
30 Correct 9 ms 6144 KB Output is correct
31 Correct 9 ms 6144 KB Output is correct
32 Correct 30 ms 6144 KB Output is correct
33 Correct 26 ms 6016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 5024 KB Output is correct
6 Correct 4 ms 5120 KB Output is correct
7 Correct 4 ms 5120 KB Output is correct
8 Correct 4 ms 5120 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 4 ms 5120 KB Output is correct
11 Correct 4 ms 5120 KB Output is correct
12 Correct 4 ms 5120 KB Output is correct
13 Correct 4 ms 5120 KB Output is correct
14 Correct 4 ms 5120 KB Output is correct
15 Correct 4 ms 5120 KB Output is correct
16 Correct 3 ms 5120 KB Output is correct
17 Correct 4 ms 5120 KB Output is correct
18 Correct 4 ms 5120 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 31 ms 5888 KB Output is correct
21 Correct 32 ms 5888 KB Output is correct
22 Correct 30 ms 6144 KB Output is correct
23 Correct 31 ms 6120 KB Output is correct
24 Correct 31 ms 6060 KB Output is correct
25 Correct 36 ms 5928 KB Output is correct
26 Correct 30 ms 6144 KB Output is correct
27 Correct 31 ms 5888 KB Output is correct
28 Correct 36 ms 5888 KB Output is correct
29 Correct 22 ms 6144 KB Output is correct
30 Correct 9 ms 6144 KB Output is correct
31 Correct 9 ms 6144 KB Output is correct
32 Correct 30 ms 6144 KB Output is correct
33 Correct 26 ms 6016 KB Output is correct
34 Correct 163 ms 25632 KB Output is correct
35 Correct 162 ms 25840 KB Output is correct
36 Correct 140 ms 31856 KB Output is correct
37 Correct 143 ms 29424 KB Output is correct
38 Correct 142 ms 27888 KB Output is correct
39 Correct 129 ms 24424 KB Output is correct
40 Correct 137 ms 31852 KB Output is correct
41 Correct 134 ms 24648 KB Output is correct
42 Correct 161 ms 25712 KB Output is correct
43 Correct 93 ms 31084 KB Output is correct
44 Correct 85 ms 31080 KB Output is correct
45 Correct 81 ms 31080 KB Output is correct
46 Correct 133 ms 31080 KB Output is correct
47 Correct 130 ms 26608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 5024 KB Output is correct
6 Correct 4 ms 5120 KB Output is correct
7 Correct 4 ms 5120 KB Output is correct
8 Correct 4 ms 5120 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 4 ms 5120 KB Output is correct
11 Correct 4 ms 5120 KB Output is correct
12 Correct 4 ms 5120 KB Output is correct
13 Correct 4 ms 5120 KB Output is correct
14 Correct 4 ms 5120 KB Output is correct
15 Correct 4 ms 5120 KB Output is correct
16 Correct 3 ms 5120 KB Output is correct
17 Correct 4 ms 5120 KB Output is correct
18 Correct 4 ms 5120 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 31 ms 5888 KB Output is correct
21 Correct 32 ms 5888 KB Output is correct
22 Correct 30 ms 6144 KB Output is correct
23 Correct 31 ms 6120 KB Output is correct
24 Correct 31 ms 6060 KB Output is correct
25 Correct 36 ms 5928 KB Output is correct
26 Correct 30 ms 6144 KB Output is correct
27 Correct 31 ms 5888 KB Output is correct
28 Correct 36 ms 5888 KB Output is correct
29 Correct 22 ms 6144 KB Output is correct
30 Correct 9 ms 6144 KB Output is correct
31 Correct 9 ms 6144 KB Output is correct
32 Correct 30 ms 6144 KB Output is correct
33 Correct 26 ms 6016 KB Output is correct
34 Correct 163 ms 25632 KB Output is correct
35 Correct 162 ms 25840 KB Output is correct
36 Correct 140 ms 31856 KB Output is correct
37 Correct 143 ms 29424 KB Output is correct
38 Correct 142 ms 27888 KB Output is correct
39 Correct 129 ms 24424 KB Output is correct
40 Correct 137 ms 31852 KB Output is correct
41 Correct 134 ms 24648 KB Output is correct
42 Correct 161 ms 25712 KB Output is correct
43 Correct 93 ms 31084 KB Output is correct
44 Correct 85 ms 31080 KB Output is correct
45 Correct 81 ms 31080 KB Output is correct
46 Correct 133 ms 31080 KB Output is correct
47 Correct 130 ms 26608 KB Output is correct
48 Correct 2236 ms 25636 KB Output is correct
49 Correct 2278 ms 25968 KB Output is correct
50 Correct 1868 ms 31852 KB Output is correct
51 Correct 1979 ms 29544 KB Output is correct
52 Correct 2071 ms 27888 KB Output is correct
53 Correct 2172 ms 24424 KB Output is correct
54 Correct 1901 ms 31852 KB Output is correct
55 Correct 2247 ms 24552 KB Output is correct
56 Correct 2221 ms 25580 KB Output is correct
57 Correct 485 ms 31080 KB Output is correct
58 Correct 377 ms 31084 KB Output is correct
59 Correct 186 ms 31116 KB Output is correct
60 Correct 2001 ms 31080 KB Output is correct
61 Correct 880 ms 30700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5042 ms 25968 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5101 ms 25964 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 5024 KB Output is correct
6 Correct 4 ms 5120 KB Output is correct
7 Correct 4 ms 5120 KB Output is correct
8 Correct 4 ms 5120 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 4 ms 5120 KB Output is correct
11 Correct 4 ms 5120 KB Output is correct
12 Correct 4 ms 5120 KB Output is correct
13 Correct 4 ms 5120 KB Output is correct
14 Correct 4 ms 5120 KB Output is correct
15 Correct 4 ms 5120 KB Output is correct
16 Correct 3 ms 5120 KB Output is correct
17 Correct 4 ms 5120 KB Output is correct
18 Correct 4 ms 5120 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 31 ms 5888 KB Output is correct
21 Correct 32 ms 5888 KB Output is correct
22 Correct 30 ms 6144 KB Output is correct
23 Correct 31 ms 6120 KB Output is correct
24 Correct 31 ms 6060 KB Output is correct
25 Correct 36 ms 5928 KB Output is correct
26 Correct 30 ms 6144 KB Output is correct
27 Correct 31 ms 5888 KB Output is correct
28 Correct 36 ms 5888 KB Output is correct
29 Correct 22 ms 6144 KB Output is correct
30 Correct 9 ms 6144 KB Output is correct
31 Correct 9 ms 6144 KB Output is correct
32 Correct 30 ms 6144 KB Output is correct
33 Correct 26 ms 6016 KB Output is correct
34 Correct 163 ms 25632 KB Output is correct
35 Correct 162 ms 25840 KB Output is correct
36 Correct 140 ms 31856 KB Output is correct
37 Correct 143 ms 29424 KB Output is correct
38 Correct 142 ms 27888 KB Output is correct
39 Correct 129 ms 24424 KB Output is correct
40 Correct 137 ms 31852 KB Output is correct
41 Correct 134 ms 24648 KB Output is correct
42 Correct 161 ms 25712 KB Output is correct
43 Correct 93 ms 31084 KB Output is correct
44 Correct 85 ms 31080 KB Output is correct
45 Correct 81 ms 31080 KB Output is correct
46 Correct 133 ms 31080 KB Output is correct
47 Correct 130 ms 26608 KB Output is correct
48 Correct 2236 ms 25636 KB Output is correct
49 Correct 2278 ms 25968 KB Output is correct
50 Correct 1868 ms 31852 KB Output is correct
51 Correct 1979 ms 29544 KB Output is correct
52 Correct 2071 ms 27888 KB Output is correct
53 Correct 2172 ms 24424 KB Output is correct
54 Correct 1901 ms 31852 KB Output is correct
55 Correct 2247 ms 24552 KB Output is correct
56 Correct 2221 ms 25580 KB Output is correct
57 Correct 485 ms 31080 KB Output is correct
58 Correct 377 ms 31084 KB Output is correct
59 Correct 186 ms 31116 KB Output is correct
60 Correct 2001 ms 31080 KB Output is correct
61 Correct 880 ms 30700 KB Output is correct
62 Execution timed out 5042 ms 25968 KB Time limit exceeded
63 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 5024 KB Output is correct
6 Correct 4 ms 5120 KB Output is correct
7 Correct 4 ms 5120 KB Output is correct
8 Correct 4 ms 5120 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 4 ms 5120 KB Output is correct
11 Correct 4 ms 5120 KB Output is correct
12 Correct 4 ms 5120 KB Output is correct
13 Correct 4 ms 5120 KB Output is correct
14 Correct 4 ms 5120 KB Output is correct
15 Correct 4 ms 5120 KB Output is correct
16 Correct 3 ms 5120 KB Output is correct
17 Correct 4 ms 5120 KB Output is correct
18 Correct 4 ms 5120 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 31 ms 5888 KB Output is correct
21 Correct 32 ms 5888 KB Output is correct
22 Correct 30 ms 6144 KB Output is correct
23 Correct 31 ms 6120 KB Output is correct
24 Correct 31 ms 6060 KB Output is correct
25 Correct 36 ms 5928 KB Output is correct
26 Correct 30 ms 6144 KB Output is correct
27 Correct 31 ms 5888 KB Output is correct
28 Correct 36 ms 5888 KB Output is correct
29 Correct 22 ms 6144 KB Output is correct
30 Correct 9 ms 6144 KB Output is correct
31 Correct 9 ms 6144 KB Output is correct
32 Correct 30 ms 6144 KB Output is correct
33 Correct 26 ms 6016 KB Output is correct
34 Correct 163 ms 25632 KB Output is correct
35 Correct 162 ms 25840 KB Output is correct
36 Correct 140 ms 31856 KB Output is correct
37 Correct 143 ms 29424 KB Output is correct
38 Correct 142 ms 27888 KB Output is correct
39 Correct 129 ms 24424 KB Output is correct
40 Correct 137 ms 31852 KB Output is correct
41 Correct 134 ms 24648 KB Output is correct
42 Correct 161 ms 25712 KB Output is correct
43 Correct 93 ms 31084 KB Output is correct
44 Correct 85 ms 31080 KB Output is correct
45 Correct 81 ms 31080 KB Output is correct
46 Correct 133 ms 31080 KB Output is correct
47 Correct 130 ms 26608 KB Output is correct
48 Correct 2236 ms 25636 KB Output is correct
49 Correct 2278 ms 25968 KB Output is correct
50 Correct 1868 ms 31852 KB Output is correct
51 Correct 1979 ms 29544 KB Output is correct
52 Correct 2071 ms 27888 KB Output is correct
53 Correct 2172 ms 24424 KB Output is correct
54 Correct 1901 ms 31852 KB Output is correct
55 Correct 2247 ms 24552 KB Output is correct
56 Correct 2221 ms 25580 KB Output is correct
57 Correct 485 ms 31080 KB Output is correct
58 Correct 377 ms 31084 KB Output is correct
59 Correct 186 ms 31116 KB Output is correct
60 Correct 2001 ms 31080 KB Output is correct
61 Correct 880 ms 30700 KB Output is correct
62 Execution timed out 5042 ms 25968 KB Time limit exceeded
63 Halted 0 ms 0 KB -