Submission #672595

# Submission time Handle Problem Language Result Execution time Memory
672595 2022-12-16T20:25:07 Z Hacv16 Dreaming (IOI13_dreaming) C++17
47 / 100
100 ms 61232 KB
#include<bits/stdc++.h>
#include"dreaming.h"
using namespace std;

const int MAX = 2e6 + 15;
const int INF = 0x3f3f3f3f;

#define fr first
#define sc second

int mxdiam, dist[MAX], pai[MAX], seen[MAX];
vector<pair<int, int>> adj[MAX];
int mx, id;

void dfs(int u, int p, int d, bool f){
	seen[u] = true;
	mxdiam = max(d, mxdiam);

	if(d > mx) mx = d, id = u;
	if(f) pai[u] = p, dist[u] = d; 

	for(auto e : adj[u]){
		int v = e.fr, w = e.sc;
		if(v == p) continue;

		dfs(v, u, d + w, f);
	}
}

int getRadius(int u){
	mx = -1, id = 0;

	dfs(u, -1, 0, 0);

	int ponta1 = id;
	mx = -1, id = 0;

	dfs(ponta1, -1, 0, 1);

	vector<int> path;
	int ponta2 = id;
	int cur = ponta2;

	while(cur != -1){
		path.push_back(cur);
		cur = pai[cur];
	}

	int mndiff = INF, idx = u;

	for(auto c : path){
		int cur = abs(dist[c] - (dist[ponta2] - dist[c]));
		if(cur < mndiff) mndiff = cur, idx = c;
	}

	return max(dist[idx], dist[ponta2] - dist[idx]);
}

int travelTime(int n, int m, int L, int A[], int B[], int T[]){
	for(int i = 0; i < m; i++){
		int u = A[i], v = B[i], w = T[i];
		adj[u].push_back({v, w});
		adj[v].push_back({u, w});
	}

	int r1 = 0, r2 = 0;

	for(int i = 0; i < n; i++){
		if(seen[i]) continue;
		int r = getRadius(i);
		
		if(r > r1){ swap(r1, r2); r1 = r; }
		else if(r > r2) { r2 = r; }
	}
	
	return max(mxdiam, L + r1 + r2);
}
# Verdict Execution time Memory Grader output
1 Correct 66 ms 58840 KB Output is correct
2 Correct 64 ms 58756 KB Output is correct
3 Correct 49 ms 54812 KB Output is correct
4 Correct 27 ms 49064 KB Output is correct
5 Correct 26 ms 48296 KB Output is correct
6 Correct 33 ms 49992 KB Output is correct
7 Correct 22 ms 47284 KB Output is correct
8 Correct 43 ms 51736 KB Output is correct
9 Correct 45 ms 53596 KB Output is correct
10 Correct 22 ms 47296 KB Output is correct
11 Correct 62 ms 55608 KB Output is correct
12 Correct 64 ms 57712 KB Output is correct
13 Correct 22 ms 47316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 47280 KB Output is correct
2 Correct 22 ms 47408 KB Output is correct
3 Correct 22 ms 47180 KB Output is correct
4 Correct 21 ms 47276 KB Output is correct
5 Correct 22 ms 47188 KB Output is correct
6 Correct 22 ms 47308 KB Output is correct
7 Correct 22 ms 47260 KB Output is correct
8 Correct 22 ms 47316 KB Output is correct
9 Correct 22 ms 47276 KB Output is correct
10 Correct 22 ms 47272 KB Output is correct
11 Correct 21 ms 47188 KB Output is correct
12 Correct 22 ms 47276 KB Output is correct
13 Correct 23 ms 47316 KB Output is correct
14 Correct 25 ms 47280 KB Output is correct
15 Correct 22 ms 47188 KB Output is correct
16 Correct 22 ms 47192 KB Output is correct
17 Correct 22 ms 47188 KB Output is correct
18 Correct 21 ms 47316 KB Output is correct
19 Correct 27 ms 47296 KB Output is correct
20 Correct 23 ms 47212 KB Output is correct
21 Correct 23 ms 47316 KB Output is correct
22 Correct 22 ms 47188 KB Output is correct
23 Correct 23 ms 47296 KB Output is correct
24 Correct 22 ms 47188 KB Output is correct
25 Correct 23 ms 47188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 58840 KB Output is correct
2 Correct 64 ms 58756 KB Output is correct
3 Correct 49 ms 54812 KB Output is correct
4 Correct 27 ms 49064 KB Output is correct
5 Correct 26 ms 48296 KB Output is correct
6 Correct 33 ms 49992 KB Output is correct
7 Correct 22 ms 47284 KB Output is correct
8 Correct 43 ms 51736 KB Output is correct
9 Correct 45 ms 53596 KB Output is correct
10 Correct 22 ms 47296 KB Output is correct
11 Correct 62 ms 55608 KB Output is correct
12 Correct 64 ms 57712 KB Output is correct
13 Correct 22 ms 47316 KB Output is correct
14 Correct 22 ms 47280 KB Output is correct
15 Correct 22 ms 47408 KB Output is correct
16 Correct 22 ms 47180 KB Output is correct
17 Correct 21 ms 47276 KB Output is correct
18 Correct 22 ms 47188 KB Output is correct
19 Correct 22 ms 47308 KB Output is correct
20 Correct 22 ms 47260 KB Output is correct
21 Correct 22 ms 47316 KB Output is correct
22 Correct 22 ms 47276 KB Output is correct
23 Correct 22 ms 47272 KB Output is correct
24 Correct 21 ms 47188 KB Output is correct
25 Correct 22 ms 47276 KB Output is correct
26 Correct 23 ms 47316 KB Output is correct
27 Correct 25 ms 47280 KB Output is correct
28 Correct 22 ms 47188 KB Output is correct
29 Correct 22 ms 47192 KB Output is correct
30 Correct 22 ms 47188 KB Output is correct
31 Correct 21 ms 47316 KB Output is correct
32 Correct 27 ms 47296 KB Output is correct
33 Correct 23 ms 47212 KB Output is correct
34 Correct 23 ms 47316 KB Output is correct
35 Correct 22 ms 47188 KB Output is correct
36 Correct 23 ms 47296 KB Output is correct
37 Correct 22 ms 47188 KB Output is correct
38 Correct 23 ms 47188 KB Output is correct
39 Correct 61 ms 59868 KB Output is correct
40 Correct 59 ms 59740 KB Output is correct
41 Correct 46 ms 55604 KB Output is correct
42 Correct 27 ms 49100 KB Output is correct
43 Correct 27 ms 47272 KB Output is correct
44 Correct 23 ms 47280 KB Output is correct
45 Correct 21 ms 47200 KB Output is correct
46 Correct 21 ms 47188 KB Output is correct
47 Correct 21 ms 47276 KB Output is correct
48 Correct 22 ms 47256 KB Output is correct
49 Correct 23 ms 47200 KB Output is correct
50 Correct 22 ms 47240 KB Output is correct
51 Correct 23 ms 47188 KB Output is correct
52 Correct 24 ms 47256 KB Output is correct
53 Correct 25 ms 47264 KB Output is correct
54 Correct 24 ms 47216 KB Output is correct
55 Correct 22 ms 47280 KB Output is correct
56 Correct 22 ms 47188 KB Output is correct
57 Correct 85 ms 54928 KB Output is correct
58 Correct 74 ms 54952 KB Output is correct
59 Correct 83 ms 54804 KB Output is correct
60 Correct 76 ms 54844 KB Output is correct
61 Correct 73 ms 55000 KB Output is correct
62 Correct 68 ms 54872 KB Output is correct
63 Correct 63 ms 54576 KB Output is correct
64 Correct 77 ms 54536 KB Output is correct
65 Correct 77 ms 54844 KB Output is correct
66 Correct 89 ms 54972 KB Output is correct
67 Correct 74 ms 54816 KB Output is correct
68 Correct 77 ms 54832 KB Output is correct
69 Correct 77 ms 55100 KB Output is correct
70 Correct 100 ms 55172 KB Output is correct
71 Correct 21 ms 47284 KB Output is correct
72 Correct 22 ms 47444 KB Output is correct
73 Correct 24 ms 47444 KB Output is correct
74 Correct 25 ms 47444 KB Output is correct
75 Correct 23 ms 47536 KB Output is correct
76 Correct 27 ms 47436 KB Output is correct
77 Correct 26 ms 47444 KB Output is correct
78 Correct 23 ms 47460 KB Output is correct
79 Correct 27 ms 47484 KB Output is correct
80 Correct 72 ms 54868 KB Output is correct
81 Correct 81 ms 54776 KB Output is correct
82 Correct 69 ms 54952 KB Output is correct
83 Correct 73 ms 54988 KB Output is correct
84 Correct 23 ms 47444 KB Output is correct
85 Correct 22 ms 47452 KB Output is correct
86 Correct 22 ms 47416 KB Output is correct
87 Correct 22 ms 47420 KB Output is correct
88 Correct 23 ms 47432 KB Output is correct
89 Correct 26 ms 47568 KB Output is correct
90 Correct 26 ms 47528 KB Output is correct
91 Correct 23 ms 47460 KB Output is correct
92 Correct 23 ms 47448 KB Output is correct
93 Correct 23 ms 47444 KB Output is correct
94 Correct 22 ms 47256 KB Output is correct
95 Correct 22 ms 47284 KB Output is correct
96 Correct 22 ms 47260 KB Output is correct
97 Correct 22 ms 47316 KB Output is correct
98 Correct 22 ms 47228 KB Output is correct
99 Correct 22 ms 47284 KB Output is correct
100 Correct 21 ms 47316 KB Output is correct
101 Correct 23 ms 47276 KB Output is correct
102 Correct 24 ms 47220 KB Output is correct
103 Correct 26 ms 47188 KB Output is correct
104 Correct 27 ms 48340 KB Output is correct
105 Correct 31 ms 50100 KB Output is correct
106 Correct 22 ms 47308 KB Output is correct
107 Correct 40 ms 51668 KB Output is correct
108 Correct 48 ms 53608 KB Output is correct
109 Correct 24 ms 47308 KB Output is correct
110 Correct 79 ms 55524 KB Output is correct
111 Correct 93 ms 57768 KB Output is correct
112 Correct 23 ms 47316 KB Output is correct
113 Correct 84 ms 61232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 50892 KB Output is correct
2 Incorrect 41 ms 50868 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 47280 KB Output is correct
2 Correct 22 ms 47408 KB Output is correct
3 Correct 22 ms 47180 KB Output is correct
4 Correct 21 ms 47276 KB Output is correct
5 Correct 22 ms 47188 KB Output is correct
6 Correct 22 ms 47308 KB Output is correct
7 Correct 22 ms 47260 KB Output is correct
8 Correct 22 ms 47316 KB Output is correct
9 Correct 22 ms 47276 KB Output is correct
10 Correct 22 ms 47272 KB Output is correct
11 Correct 21 ms 47188 KB Output is correct
12 Correct 22 ms 47276 KB Output is correct
13 Correct 23 ms 47316 KB Output is correct
14 Correct 25 ms 47280 KB Output is correct
15 Correct 22 ms 47188 KB Output is correct
16 Correct 22 ms 47192 KB Output is correct
17 Correct 22 ms 47188 KB Output is correct
18 Correct 21 ms 47316 KB Output is correct
19 Correct 27 ms 47296 KB Output is correct
20 Correct 23 ms 47212 KB Output is correct
21 Correct 23 ms 47316 KB Output is correct
22 Correct 22 ms 47188 KB Output is correct
23 Correct 23 ms 47296 KB Output is correct
24 Correct 22 ms 47188 KB Output is correct
25 Correct 23 ms 47188 KB Output is correct
26 Correct 24 ms 47316 KB Output is correct
27 Correct 25 ms 47352 KB Output is correct
28 Correct 31 ms 47400 KB Output is correct
29 Correct 25 ms 47376 KB Output is correct
30 Correct 27 ms 47412 KB Output is correct
31 Correct 22 ms 47444 KB Output is correct
32 Incorrect 23 ms 47356 KB Output isn't correct
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 66 ms 58840 KB Output is correct
2 Correct 64 ms 58756 KB Output is correct
3 Correct 49 ms 54812 KB Output is correct
4 Correct 27 ms 49064 KB Output is correct
5 Correct 26 ms 48296 KB Output is correct
6 Correct 33 ms 49992 KB Output is correct
7 Correct 22 ms 47284 KB Output is correct
8 Correct 43 ms 51736 KB Output is correct
9 Correct 45 ms 53596 KB Output is correct
10 Correct 22 ms 47296 KB Output is correct
11 Correct 62 ms 55608 KB Output is correct
12 Correct 64 ms 57712 KB Output is correct
13 Correct 22 ms 47316 KB Output is correct
14 Correct 22 ms 47280 KB Output is correct
15 Correct 22 ms 47408 KB Output is correct
16 Correct 22 ms 47180 KB Output is correct
17 Correct 21 ms 47276 KB Output is correct
18 Correct 22 ms 47188 KB Output is correct
19 Correct 22 ms 47308 KB Output is correct
20 Correct 22 ms 47260 KB Output is correct
21 Correct 22 ms 47316 KB Output is correct
22 Correct 22 ms 47276 KB Output is correct
23 Correct 22 ms 47272 KB Output is correct
24 Correct 21 ms 47188 KB Output is correct
25 Correct 22 ms 47276 KB Output is correct
26 Correct 23 ms 47316 KB Output is correct
27 Correct 25 ms 47280 KB Output is correct
28 Correct 22 ms 47188 KB Output is correct
29 Correct 22 ms 47192 KB Output is correct
30 Correct 22 ms 47188 KB Output is correct
31 Correct 21 ms 47316 KB Output is correct
32 Correct 27 ms 47296 KB Output is correct
33 Correct 23 ms 47212 KB Output is correct
34 Correct 23 ms 47316 KB Output is correct
35 Correct 22 ms 47188 KB Output is correct
36 Correct 23 ms 47296 KB Output is correct
37 Correct 22 ms 47188 KB Output is correct
38 Correct 23 ms 47188 KB Output is correct
39 Correct 61 ms 59868 KB Output is correct
40 Correct 59 ms 59740 KB Output is correct
41 Correct 46 ms 55604 KB Output is correct
42 Correct 27 ms 49100 KB Output is correct
43 Correct 27 ms 47272 KB Output is correct
44 Correct 23 ms 47280 KB Output is correct
45 Correct 21 ms 47200 KB Output is correct
46 Correct 21 ms 47188 KB Output is correct
47 Correct 21 ms 47276 KB Output is correct
48 Correct 22 ms 47256 KB Output is correct
49 Correct 23 ms 47200 KB Output is correct
50 Correct 22 ms 47240 KB Output is correct
51 Correct 23 ms 47188 KB Output is correct
52 Correct 24 ms 47256 KB Output is correct
53 Correct 25 ms 47264 KB Output is correct
54 Correct 24 ms 47216 KB Output is correct
55 Correct 22 ms 47280 KB Output is correct
56 Correct 22 ms 47188 KB Output is correct
57 Correct 85 ms 54928 KB Output is correct
58 Correct 74 ms 54952 KB Output is correct
59 Correct 83 ms 54804 KB Output is correct
60 Correct 76 ms 54844 KB Output is correct
61 Correct 73 ms 55000 KB Output is correct
62 Correct 68 ms 54872 KB Output is correct
63 Correct 63 ms 54576 KB Output is correct
64 Correct 77 ms 54536 KB Output is correct
65 Correct 77 ms 54844 KB Output is correct
66 Correct 89 ms 54972 KB Output is correct
67 Correct 74 ms 54816 KB Output is correct
68 Correct 77 ms 54832 KB Output is correct
69 Correct 77 ms 55100 KB Output is correct
70 Correct 100 ms 55172 KB Output is correct
71 Correct 21 ms 47284 KB Output is correct
72 Correct 22 ms 47444 KB Output is correct
73 Correct 24 ms 47444 KB Output is correct
74 Correct 25 ms 47444 KB Output is correct
75 Correct 23 ms 47536 KB Output is correct
76 Correct 27 ms 47436 KB Output is correct
77 Correct 26 ms 47444 KB Output is correct
78 Correct 23 ms 47460 KB Output is correct
79 Correct 27 ms 47484 KB Output is correct
80 Correct 72 ms 54868 KB Output is correct
81 Correct 81 ms 54776 KB Output is correct
82 Correct 69 ms 54952 KB Output is correct
83 Correct 73 ms 54988 KB Output is correct
84 Correct 23 ms 47444 KB Output is correct
85 Correct 22 ms 47452 KB Output is correct
86 Correct 22 ms 47416 KB Output is correct
87 Correct 22 ms 47420 KB Output is correct
88 Correct 23 ms 47432 KB Output is correct
89 Correct 26 ms 47568 KB Output is correct
90 Correct 26 ms 47528 KB Output is correct
91 Correct 23 ms 47460 KB Output is correct
92 Correct 23 ms 47448 KB Output is correct
93 Correct 23 ms 47444 KB Output is correct
94 Correct 22 ms 47256 KB Output is correct
95 Correct 22 ms 47284 KB Output is correct
96 Correct 22 ms 47260 KB Output is correct
97 Correct 22 ms 47316 KB Output is correct
98 Correct 22 ms 47228 KB Output is correct
99 Correct 22 ms 47284 KB Output is correct
100 Correct 21 ms 47316 KB Output is correct
101 Correct 23 ms 47276 KB Output is correct
102 Correct 24 ms 47220 KB Output is correct
103 Correct 26 ms 47188 KB Output is correct
104 Correct 27 ms 48340 KB Output is correct
105 Correct 31 ms 50100 KB Output is correct
106 Correct 22 ms 47308 KB Output is correct
107 Correct 40 ms 51668 KB Output is correct
108 Correct 48 ms 53608 KB Output is correct
109 Correct 24 ms 47308 KB Output is correct
110 Correct 79 ms 55524 KB Output is correct
111 Correct 93 ms 57768 KB Output is correct
112 Correct 23 ms 47316 KB Output is correct
113 Correct 84 ms 61232 KB Output is correct
114 Correct 41 ms 50892 KB Output is correct
115 Incorrect 41 ms 50868 KB Output isn't correct
116 Halted 0 ms 0 KB -