Submission #475689

# Submission time Handle Problem Language Result Execution time Memory
475689 2021-09-23T16:42:29 Z AdamGS Race (IOI11_race) C++14
100 / 100
539 ms 36460 KB
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=2e5+7, MAXK=1e6+7;
vector<pair<int,int>>V[LIM];
int usuniete[LIM], ile[LIM], rozmiar, ans, n, k, nr;
pair<int,int>T[MAXK];
queue<int>q;
void DFS(int x, int o) {
	q.push(x);
	++rozmiar;
	ile[x]=1;
	for(auto i : V[x]) if(i.st!=o && !usuniete[i.st]) {
		DFS(i.st, x);
		ile[x]+=ile[i.st];
	}
}
int znajdz(int x) {
	rozmiar=0;
	DFS(x, x);
	int ma=LIM, cent=-1;
	while(!q.empty()) {
		int p=q.front(), akt=rozmiar-ile[p]; q.pop();
		for(auto i : V[p]) if(!usuniete[i.st]) {
			if(ile[i.st]<ile[p]) akt=max(akt, ile[i.st]);
		}
		if(akt<ma) {
			ma=akt;
			cent=p;
		}
	}
	return cent;
}
void licz(int x, int o, int v, int g) {
	if(v>k) v=k+1;
	if(v<=k && T[k-v].nd==nr) {
		ans=min(ans, T[k-v].st+g);
	}
	for(auto i : V[x]) if(i.st!=o && !usuniete[i.st]) licz(i.st, x, v+i.nd, g+1);
}
void ustaw(int x, int o, int v, int g) {
	if(v>k) v=k+1;
	if(v<=k) {
		if(T[v].nd<nr || T[v].st>g) T[v]={g, nr};
	}
	for(auto i : V[x]) if(i.st!=o && !usuniete[i.st]) ustaw(i.st, x, v+i.nd, g+1);
}
void cd(int x) {
	int p=znajdz(x);
	usuniete[p]=1;
	++nr;
	T[0]={0, nr};
	for(auto i : V[p]) if(!usuniete[i.st]) {
		licz(i.st, p, i.nd, 1);
		ustaw(i.st, p, i.nd, 1);
	}
	for(auto i : V[p]) if(!usuniete[i.st]) cd(i.st);
}
int best_path(int N, int K, int h[][2], int l[]) {
	n=N; k=K;
	rep(i, n-1) {
		V[h[i][0]].pb({h[i][1], l[i]});
		V[h[i][1]].pb({h[i][0], l[i]});
	}
	ans=LIM;
	cd(0);
	if(ans==LIM) return -1;
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 4 ms 5068 KB Output is correct
22 Correct 6 ms 8296 KB Output is correct
23 Correct 6 ms 8012 KB Output is correct
24 Correct 7 ms 9108 KB Output is correct
25 Correct 7 ms 8268 KB Output is correct
26 Correct 5 ms 7372 KB Output is correct
27 Correct 4 ms 5068 KB Output is correct
28 Correct 4 ms 6604 KB Output is correct
29 Correct 6 ms 7500 KB Output is correct
30 Correct 6 ms 7756 KB Output is correct
31 Correct 6 ms 8396 KB Output is correct
32 Correct 7 ms 8340 KB Output is correct
33 Correct 8 ms 9804 KB Output is correct
34 Correct 6 ms 9036 KB Output is correct
35 Correct 7 ms 10060 KB Output is correct
36 Correct 7 ms 10316 KB Output is correct
37 Correct 6 ms 8268 KB Output is correct
38 Correct 5 ms 7244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 167 ms 11000 KB Output is correct
20 Correct 162 ms 10980 KB Output is correct
21 Correct 162 ms 11120 KB Output is correct
22 Correct 134 ms 10996 KB Output is correct
23 Correct 130 ms 11220 KB Output is correct
24 Correct 75 ms 11076 KB Output is correct
25 Correct 145 ms 13664 KB Output is correct
26 Correct 97 ms 16684 KB Output is correct
27 Correct 239 ms 17188 KB Output is correct
28 Correct 402 ms 28224 KB Output is correct
29 Correct 419 ms 27372 KB Output is correct
30 Correct 201 ms 17220 KB Output is correct
31 Correct 203 ms 17284 KB Output is correct
32 Correct 291 ms 17220 KB Output is correct
33 Correct 323 ms 15780 KB Output is correct
34 Correct 329 ms 15968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 4 ms 5068 KB Output is correct
22 Correct 6 ms 8296 KB Output is correct
23 Correct 6 ms 8012 KB Output is correct
24 Correct 7 ms 9108 KB Output is correct
25 Correct 7 ms 8268 KB Output is correct
26 Correct 5 ms 7372 KB Output is correct
27 Correct 4 ms 5068 KB Output is correct
28 Correct 4 ms 6604 KB Output is correct
29 Correct 6 ms 7500 KB Output is correct
30 Correct 6 ms 7756 KB Output is correct
31 Correct 6 ms 8396 KB Output is correct
32 Correct 7 ms 8340 KB Output is correct
33 Correct 8 ms 9804 KB Output is correct
34 Correct 6 ms 9036 KB Output is correct
35 Correct 7 ms 10060 KB Output is correct
36 Correct 7 ms 10316 KB Output is correct
37 Correct 6 ms 8268 KB Output is correct
38 Correct 5 ms 7244 KB Output is correct
39 Correct 167 ms 11000 KB Output is correct
40 Correct 162 ms 10980 KB Output is correct
41 Correct 162 ms 11120 KB Output is correct
42 Correct 134 ms 10996 KB Output is correct
43 Correct 130 ms 11220 KB Output is correct
44 Correct 75 ms 11076 KB Output is correct
45 Correct 145 ms 13664 KB Output is correct
46 Correct 97 ms 16684 KB Output is correct
47 Correct 239 ms 17188 KB Output is correct
48 Correct 402 ms 28224 KB Output is correct
49 Correct 419 ms 27372 KB Output is correct
50 Correct 201 ms 17220 KB Output is correct
51 Correct 203 ms 17284 KB Output is correct
52 Correct 291 ms 17220 KB Output is correct
53 Correct 323 ms 15780 KB Output is correct
54 Correct 329 ms 15968 KB Output is correct
55 Correct 13 ms 5768 KB Output is correct
56 Correct 14 ms 5708 KB Output is correct
57 Correct 86 ms 12464 KB Output is correct
58 Correct 39 ms 12328 KB Output is correct
59 Correct 99 ms 18808 KB Output is correct
60 Correct 459 ms 35168 KB Output is correct
61 Correct 202 ms 20368 KB Output is correct
62 Correct 206 ms 20424 KB Output is correct
63 Correct 288 ms 20408 KB Output is correct
64 Correct 539 ms 22576 KB Output is correct
65 Correct 377 ms 20868 KB Output is correct
66 Correct 527 ms 36460 KB Output is correct
67 Correct 123 ms 20916 KB Output is correct
68 Correct 305 ms 26180 KB Output is correct
69 Correct 293 ms 26564 KB Output is correct
70 Correct 307 ms 25376 KB Output is correct