# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1074007 |
2024-08-25T06:24:03 Z |
Ignut |
Dreaming (IOI13_dreaming) |
C++17 |
|
110 ms |
18900 KB |
// Ignut
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
using ll = long long;
const int INF = 1e9 + 123;
const int MAXN = 1e5 + 123;
vector<pair<int, int>> tree[MAXN];
int dist[MAXN];
void dfs(int v, int par, int d) {
dist[v] = d;
for (auto [to, w] : tree[v])
if (to != par)
dfs(to, v, d + w);
}
void FindDist(int source) {
dfs(source, -1, 0);
}
bool used[MAXN];
vector<int> comp;
void dfs0(int v, int par = -1) {
used[v] = true;
comp.push_back(v);
for (auto [to, w] : tree[v])
if (to != par)
dfs0(to, v);
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for (int i = 0; i < N; i ++) {
tree[i].clear();
used[i] = false;
}
for (int i = 0; i < M; i ++) {
tree[A[i]].push_back({B[i], T[i]});
tree[B[i]].push_back({A[i], T[i]});
}
vector<int> c;
for (int i = 0; i < N; i ++) {
if (used[i]) continue;
comp.clear();
dfs0(i);
FindDist(i);
int j = i;
for (int v : comp) if (dist[v] > dist[j]) j = v;
FindDist(j);
map<int, int> d1;
for (int v : comp) d1[v] = dist[v];
j = i;
for (int v : comp) if (dist[v] > dist[j]) j = v;
FindDist(j);
int ctr = i, maxDist = INF;
for (int v : comp) {
// FindDist(j);
int d = max(d1[v], dist[v]);
// int dd = 0;
// FindDist(v);
// for (int u : comp) dd = max(dd, dist[u]);
// if (d != dd) {
// cout << "not equal!!!\n";
// cout << v << " : " << d << ' ' << dd << '\n';
// // N /= 0;
// }
// d = dd;
if (d < maxDist) {
ctr = v;
maxDist = d;
}
}
c.push_back(ctr);
// cout << "-- " << ctr << '\n';
}
if (c.size() == 2) {
tree[c[0]].push_back({c[1], L});
tree[c[1]].push_back({c[0], L});
}
int res = 0;
FindDist(0);
int j = 0;
for (int i = 0; i < N; i ++) if (dist[i] > dist[j]) j = i;
FindDist(j);
for (int i = 0; i < N; i ++) res = max(res, dist[i]);
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
15568 KB |
Output is correct |
2 |
Correct |
79 ms |
15300 KB |
Output is correct |
3 |
Correct |
51 ms |
11864 KB |
Output is correct |
4 |
Correct |
10 ms |
4700 KB |
Output is correct |
5 |
Correct |
9 ms |
3816 KB |
Output is correct |
6 |
Correct |
18 ms |
5504 KB |
Output is correct |
7 |
Correct |
2 ms |
2648 KB |
Output is correct |
8 |
Correct |
37 ms |
7236 KB |
Output is correct |
9 |
Correct |
50 ms |
9700 KB |
Output is correct |
10 |
Correct |
2 ms |
2652 KB |
Output is correct |
11 |
Correct |
69 ms |
11148 KB |
Output is correct |
12 |
Correct |
89 ms |
13012 KB |
Output is correct |
13 |
Correct |
2 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
2 ms |
2648 KB |
Output is correct |
6 |
Correct |
2 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
2 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2788 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
2 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2800 KB |
Output is correct |
21 |
Correct |
2 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2780 KB |
Output is correct |
24 |
Correct |
2 ms |
2652 KB |
Output is correct |
25 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
15568 KB |
Output is correct |
2 |
Correct |
79 ms |
15300 KB |
Output is correct |
3 |
Correct |
51 ms |
11864 KB |
Output is correct |
4 |
Correct |
10 ms |
4700 KB |
Output is correct |
5 |
Correct |
9 ms |
3816 KB |
Output is correct |
6 |
Correct |
18 ms |
5504 KB |
Output is correct |
7 |
Correct |
2 ms |
2648 KB |
Output is correct |
8 |
Correct |
37 ms |
7236 KB |
Output is correct |
9 |
Correct |
50 ms |
9700 KB |
Output is correct |
10 |
Correct |
2 ms |
2652 KB |
Output is correct |
11 |
Correct |
69 ms |
11148 KB |
Output is correct |
12 |
Correct |
89 ms |
13012 KB |
Output is correct |
13 |
Correct |
2 ms |
2908 KB |
Output is correct |
14 |
Correct |
2 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2648 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
2 ms |
2648 KB |
Output is correct |
19 |
Correct |
2 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
1 ms |
2788 KB |
Output is correct |
29 |
Correct |
1 ms |
2652 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
1 ms |
2652 KB |
Output is correct |
32 |
Correct |
2 ms |
2652 KB |
Output is correct |
33 |
Correct |
1 ms |
2800 KB |
Output is correct |
34 |
Correct |
2 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
1 ms |
2780 KB |
Output is correct |
37 |
Correct |
2 ms |
2652 KB |
Output is correct |
38 |
Correct |
2 ms |
2652 KB |
Output is correct |
39 |
Correct |
82 ms |
15568 KB |
Output is correct |
40 |
Correct |
78 ms |
15304 KB |
Output is correct |
41 |
Correct |
58 ms |
11972 KB |
Output is correct |
42 |
Correct |
10 ms |
4444 KB |
Output is correct |
43 |
Correct |
1 ms |
2804 KB |
Output is correct |
44 |
Correct |
2 ms |
2648 KB |
Output is correct |
45 |
Correct |
2 ms |
2652 KB |
Output is correct |
46 |
Correct |
1 ms |
2652 KB |
Output is correct |
47 |
Correct |
1 ms |
2652 KB |
Output is correct |
48 |
Correct |
1 ms |
2648 KB |
Output is correct |
49 |
Correct |
2 ms |
2652 KB |
Output is correct |
50 |
Correct |
1 ms |
2652 KB |
Output is correct |
51 |
Correct |
1 ms |
2652 KB |
Output is correct |
52 |
Correct |
1 ms |
2652 KB |
Output is correct |
53 |
Correct |
2 ms |
2652 KB |
Output is correct |
54 |
Correct |
1 ms |
2652 KB |
Output is correct |
55 |
Correct |
1 ms |
2652 KB |
Output is correct |
56 |
Correct |
1 ms |
2652 KB |
Output is correct |
57 |
Correct |
103 ms |
14372 KB |
Output is correct |
58 |
Correct |
98 ms |
12496 KB |
Output is correct |
59 |
Correct |
110 ms |
13996 KB |
Output is correct |
60 |
Correct |
98 ms |
12072 KB |
Output is correct |
61 |
Correct |
96 ms |
14024 KB |
Output is correct |
62 |
Correct |
98 ms |
13012 KB |
Output is correct |
63 |
Correct |
94 ms |
14432 KB |
Output is correct |
64 |
Correct |
90 ms |
14548 KB |
Output is correct |
65 |
Correct |
95 ms |
14620 KB |
Output is correct |
66 |
Correct |
94 ms |
14796 KB |
Output is correct |
67 |
Correct |
104 ms |
14008 KB |
Output is correct |
68 |
Correct |
98 ms |
14020 KB |
Output is correct |
69 |
Correct |
92 ms |
12752 KB |
Output is correct |
70 |
Correct |
98 ms |
12752 KB |
Output is correct |
71 |
Correct |
1 ms |
2652 KB |
Output is correct |
72 |
Correct |
3 ms |
2908 KB |
Output is correct |
73 |
Correct |
4 ms |
2908 KB |
Output is correct |
74 |
Correct |
3 ms |
3068 KB |
Output is correct |
75 |
Correct |
3 ms |
3068 KB |
Output is correct |
76 |
Correct |
3 ms |
2908 KB |
Output is correct |
77 |
Correct |
3 ms |
2968 KB |
Output is correct |
78 |
Correct |
3 ms |
2908 KB |
Output is correct |
79 |
Correct |
5 ms |
3116 KB |
Output is correct |
80 |
Correct |
96 ms |
13008 KB |
Output is correct |
81 |
Correct |
97 ms |
13000 KB |
Output is correct |
82 |
Correct |
97 ms |
14052 KB |
Output is correct |
83 |
Correct |
93 ms |
14688 KB |
Output is correct |
84 |
Correct |
2 ms |
2844 KB |
Output is correct |
85 |
Correct |
3 ms |
2908 KB |
Output is correct |
86 |
Correct |
2 ms |
2908 KB |
Output is correct |
87 |
Correct |
3 ms |
2908 KB |
Output is correct |
88 |
Correct |
2 ms |
2908 KB |
Output is correct |
89 |
Correct |
3 ms |
2908 KB |
Output is correct |
90 |
Correct |
2 ms |
2908 KB |
Output is correct |
91 |
Correct |
3 ms |
2908 KB |
Output is correct |
92 |
Correct |
3 ms |
2908 KB |
Output is correct |
93 |
Correct |
3 ms |
2908 KB |
Output is correct |
94 |
Correct |
1 ms |
2652 KB |
Output is correct |
95 |
Correct |
1 ms |
2652 KB |
Output is correct |
96 |
Correct |
1 ms |
2652 KB |
Output is correct |
97 |
Correct |
1 ms |
2800 KB |
Output is correct |
98 |
Correct |
1 ms |
2652 KB |
Output is correct |
99 |
Correct |
1 ms |
2652 KB |
Output is correct |
100 |
Correct |
1 ms |
2652 KB |
Output is correct |
101 |
Correct |
1 ms |
2652 KB |
Output is correct |
102 |
Correct |
1 ms |
2652 KB |
Output is correct |
103 |
Correct |
1 ms |
2652 KB |
Output is correct |
104 |
Correct |
8 ms |
3676 KB |
Output is correct |
105 |
Correct |
21 ms |
5464 KB |
Output is correct |
106 |
Correct |
2 ms |
2648 KB |
Output is correct |
107 |
Correct |
36 ms |
7276 KB |
Output is correct |
108 |
Correct |
47 ms |
9684 KB |
Output is correct |
109 |
Correct |
2 ms |
2648 KB |
Output is correct |
110 |
Correct |
65 ms |
11224 KB |
Output is correct |
111 |
Correct |
84 ms |
13104 KB |
Output is correct |
112 |
Correct |
2 ms |
2908 KB |
Output is correct |
113 |
Correct |
109 ms |
18900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
6384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
2 ms |
2648 KB |
Output is correct |
6 |
Correct |
2 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
2 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2788 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
2 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2800 KB |
Output is correct |
21 |
Correct |
2 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2780 KB |
Output is correct |
24 |
Correct |
2 ms |
2652 KB |
Output is correct |
25 |
Correct |
2 ms |
2652 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
2 ms |
2844 KB |
Output is correct |
28 |
Correct |
2 ms |
2908 KB |
Output is correct |
29 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
15568 KB |
Output is correct |
2 |
Correct |
79 ms |
15300 KB |
Output is correct |
3 |
Correct |
51 ms |
11864 KB |
Output is correct |
4 |
Correct |
10 ms |
4700 KB |
Output is correct |
5 |
Correct |
9 ms |
3816 KB |
Output is correct |
6 |
Correct |
18 ms |
5504 KB |
Output is correct |
7 |
Correct |
2 ms |
2648 KB |
Output is correct |
8 |
Correct |
37 ms |
7236 KB |
Output is correct |
9 |
Correct |
50 ms |
9700 KB |
Output is correct |
10 |
Correct |
2 ms |
2652 KB |
Output is correct |
11 |
Correct |
69 ms |
11148 KB |
Output is correct |
12 |
Correct |
89 ms |
13012 KB |
Output is correct |
13 |
Correct |
2 ms |
2908 KB |
Output is correct |
14 |
Correct |
2 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2648 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
2 ms |
2648 KB |
Output is correct |
19 |
Correct |
2 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
1 ms |
2788 KB |
Output is correct |
29 |
Correct |
1 ms |
2652 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
1 ms |
2652 KB |
Output is correct |
32 |
Correct |
2 ms |
2652 KB |
Output is correct |
33 |
Correct |
1 ms |
2800 KB |
Output is correct |
34 |
Correct |
2 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
1 ms |
2780 KB |
Output is correct |
37 |
Correct |
2 ms |
2652 KB |
Output is correct |
38 |
Correct |
2 ms |
2652 KB |
Output is correct |
39 |
Correct |
82 ms |
15568 KB |
Output is correct |
40 |
Correct |
78 ms |
15304 KB |
Output is correct |
41 |
Correct |
58 ms |
11972 KB |
Output is correct |
42 |
Correct |
10 ms |
4444 KB |
Output is correct |
43 |
Correct |
1 ms |
2804 KB |
Output is correct |
44 |
Correct |
2 ms |
2648 KB |
Output is correct |
45 |
Correct |
2 ms |
2652 KB |
Output is correct |
46 |
Correct |
1 ms |
2652 KB |
Output is correct |
47 |
Correct |
1 ms |
2652 KB |
Output is correct |
48 |
Correct |
1 ms |
2648 KB |
Output is correct |
49 |
Correct |
2 ms |
2652 KB |
Output is correct |
50 |
Correct |
1 ms |
2652 KB |
Output is correct |
51 |
Correct |
1 ms |
2652 KB |
Output is correct |
52 |
Correct |
1 ms |
2652 KB |
Output is correct |
53 |
Correct |
2 ms |
2652 KB |
Output is correct |
54 |
Correct |
1 ms |
2652 KB |
Output is correct |
55 |
Correct |
1 ms |
2652 KB |
Output is correct |
56 |
Correct |
1 ms |
2652 KB |
Output is correct |
57 |
Correct |
103 ms |
14372 KB |
Output is correct |
58 |
Correct |
98 ms |
12496 KB |
Output is correct |
59 |
Correct |
110 ms |
13996 KB |
Output is correct |
60 |
Correct |
98 ms |
12072 KB |
Output is correct |
61 |
Correct |
96 ms |
14024 KB |
Output is correct |
62 |
Correct |
98 ms |
13012 KB |
Output is correct |
63 |
Correct |
94 ms |
14432 KB |
Output is correct |
64 |
Correct |
90 ms |
14548 KB |
Output is correct |
65 |
Correct |
95 ms |
14620 KB |
Output is correct |
66 |
Correct |
94 ms |
14796 KB |
Output is correct |
67 |
Correct |
104 ms |
14008 KB |
Output is correct |
68 |
Correct |
98 ms |
14020 KB |
Output is correct |
69 |
Correct |
92 ms |
12752 KB |
Output is correct |
70 |
Correct |
98 ms |
12752 KB |
Output is correct |
71 |
Correct |
1 ms |
2652 KB |
Output is correct |
72 |
Correct |
3 ms |
2908 KB |
Output is correct |
73 |
Correct |
4 ms |
2908 KB |
Output is correct |
74 |
Correct |
3 ms |
3068 KB |
Output is correct |
75 |
Correct |
3 ms |
3068 KB |
Output is correct |
76 |
Correct |
3 ms |
2908 KB |
Output is correct |
77 |
Correct |
3 ms |
2968 KB |
Output is correct |
78 |
Correct |
3 ms |
2908 KB |
Output is correct |
79 |
Correct |
5 ms |
3116 KB |
Output is correct |
80 |
Correct |
96 ms |
13008 KB |
Output is correct |
81 |
Correct |
97 ms |
13000 KB |
Output is correct |
82 |
Correct |
97 ms |
14052 KB |
Output is correct |
83 |
Correct |
93 ms |
14688 KB |
Output is correct |
84 |
Correct |
2 ms |
2844 KB |
Output is correct |
85 |
Correct |
3 ms |
2908 KB |
Output is correct |
86 |
Correct |
2 ms |
2908 KB |
Output is correct |
87 |
Correct |
3 ms |
2908 KB |
Output is correct |
88 |
Correct |
2 ms |
2908 KB |
Output is correct |
89 |
Correct |
3 ms |
2908 KB |
Output is correct |
90 |
Correct |
2 ms |
2908 KB |
Output is correct |
91 |
Correct |
3 ms |
2908 KB |
Output is correct |
92 |
Correct |
3 ms |
2908 KB |
Output is correct |
93 |
Correct |
3 ms |
2908 KB |
Output is correct |
94 |
Correct |
1 ms |
2652 KB |
Output is correct |
95 |
Correct |
1 ms |
2652 KB |
Output is correct |
96 |
Correct |
1 ms |
2652 KB |
Output is correct |
97 |
Correct |
1 ms |
2800 KB |
Output is correct |
98 |
Correct |
1 ms |
2652 KB |
Output is correct |
99 |
Correct |
1 ms |
2652 KB |
Output is correct |
100 |
Correct |
1 ms |
2652 KB |
Output is correct |
101 |
Correct |
1 ms |
2652 KB |
Output is correct |
102 |
Correct |
1 ms |
2652 KB |
Output is correct |
103 |
Correct |
1 ms |
2652 KB |
Output is correct |
104 |
Correct |
8 ms |
3676 KB |
Output is correct |
105 |
Correct |
21 ms |
5464 KB |
Output is correct |
106 |
Correct |
2 ms |
2648 KB |
Output is correct |
107 |
Correct |
36 ms |
7276 KB |
Output is correct |
108 |
Correct |
47 ms |
9684 KB |
Output is correct |
109 |
Correct |
2 ms |
2648 KB |
Output is correct |
110 |
Correct |
65 ms |
11224 KB |
Output is correct |
111 |
Correct |
84 ms |
13104 KB |
Output is correct |
112 |
Correct |
2 ms |
2908 KB |
Output is correct |
113 |
Correct |
109 ms |
18900 KB |
Output is correct |
114 |
Incorrect |
17 ms |
6384 KB |
Output isn't correct |
115 |
Halted |
0 ms |
0 KB |
- |