#include <dreaming.h>
#include <iostream>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define trav(x, v) for (auto &x : v)
#define eb(x...) emplace_back(x)
using pii = pair<int, int>;
template<class T> bool ckmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
constexpr int N = 1 << 17;
vector<pii> g[N];
int d[N], p[N], a;
bool vis[N];
void dfs(int u, int p = -1) {
if (d[u] > d[a]) a = u;
::p[u] = p;
vis[u] = true;
trav(e, g[u]) {
int v, w; tie(v, w) = e;
if (v == p) continue;
d[v] = d[u] + w;
dfs(v, u);
}
}
int travelTime(int n, int m, int l, int A[], int B[], int T[]) {
rep(i, 0, m) {
g[A[i]].eb(B[i], T[i]);
g[B[i]].eb(A[i], T[i]);
}
int ans = 0, one = 0, two = 0;
rep(u, 0, n) {
if (vis[u]) continue;
a = u; d[u] = 0; dfs(u);
d[a] = 0; dfs(a);
int e = d[a]; ckmax(ans, d[a]);
for (int v = a; p[v] != -1; v = p[v])
ckmin(e, max(d[a] - d[v], d[v]));
if (one <= e) two = one, one = e;
else if (two < e) two = e;
}
return two ? max(ans, one + two + l) : ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
13688 KB |
Output is correct |
2 |
Correct |
57 ms |
13560 KB |
Output is correct |
3 |
Correct |
44 ms |
10360 KB |
Output is correct |
4 |
Correct |
14 ms |
4992 KB |
Output is correct |
5 |
Correct |
12 ms |
4352 KB |
Output is correct |
6 |
Correct |
18 ms |
5760 KB |
Output is correct |
7 |
Correct |
6 ms |
3456 KB |
Output is correct |
8 |
Correct |
30 ms |
7160 KB |
Output is correct |
9 |
Correct |
44 ms |
8568 KB |
Output is correct |
10 |
Correct |
8 ms |
3456 KB |
Output is correct |
11 |
Correct |
63 ms |
10488 KB |
Output is correct |
12 |
Correct |
73 ms |
11896 KB |
Output is correct |
13 |
Correct |
7 ms |
3584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
13688 KB |
Output is correct |
2 |
Correct |
57 ms |
13560 KB |
Output is correct |
3 |
Correct |
44 ms |
10360 KB |
Output is correct |
4 |
Correct |
14 ms |
4992 KB |
Output is correct |
5 |
Correct |
12 ms |
4352 KB |
Output is correct |
6 |
Correct |
18 ms |
5760 KB |
Output is correct |
7 |
Correct |
6 ms |
3456 KB |
Output is correct |
8 |
Correct |
30 ms |
7160 KB |
Output is correct |
9 |
Correct |
44 ms |
8568 KB |
Output is correct |
10 |
Correct |
8 ms |
3456 KB |
Output is correct |
11 |
Correct |
63 ms |
10488 KB |
Output is correct |
12 |
Correct |
73 ms |
11896 KB |
Output is correct |
13 |
Correct |
7 ms |
3584 KB |
Output is correct |
14 |
Correct |
6 ms |
3456 KB |
Output is correct |
15 |
Correct |
6 ms |
3456 KB |
Output is correct |
16 |
Correct |
7 ms |
3456 KB |
Output is correct |
17 |
Correct |
7 ms |
3456 KB |
Output is correct |
18 |
Correct |
7 ms |
3456 KB |
Output is correct |
19 |
Correct |
6 ms |
3456 KB |
Output is correct |
20 |
Correct |
6 ms |
3456 KB |
Output is correct |
21 |
Correct |
6 ms |
3456 KB |
Output is correct |
22 |
Correct |
6 ms |
3456 KB |
Output is correct |
23 |
Correct |
6 ms |
3456 KB |
Output is correct |
24 |
Correct |
6 ms |
3456 KB |
Output is correct |
25 |
Correct |
6 ms |
3456 KB |
Output is correct |
26 |
Correct |
6 ms |
3456 KB |
Output is correct |
27 |
Correct |
6 ms |
3456 KB |
Output is correct |
28 |
Incorrect |
6 ms |
3456 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
13688 KB |
Output is correct |
2 |
Correct |
57 ms |
13560 KB |
Output is correct |
3 |
Correct |
44 ms |
10360 KB |
Output is correct |
4 |
Correct |
14 ms |
4992 KB |
Output is correct |
5 |
Correct |
12 ms |
4352 KB |
Output is correct |
6 |
Correct |
18 ms |
5760 KB |
Output is correct |
7 |
Correct |
6 ms |
3456 KB |
Output is correct |
8 |
Correct |
30 ms |
7160 KB |
Output is correct |
9 |
Correct |
44 ms |
8568 KB |
Output is correct |
10 |
Correct |
8 ms |
3456 KB |
Output is correct |
11 |
Correct |
63 ms |
10488 KB |
Output is correct |
12 |
Correct |
73 ms |
11896 KB |
Output is correct |
13 |
Correct |
7 ms |
3584 KB |
Output is correct |
14 |
Correct |
6 ms |
3456 KB |
Output is correct |
15 |
Correct |
6 ms |
3456 KB |
Output is correct |
16 |
Correct |
7 ms |
3456 KB |
Output is correct |
17 |
Correct |
7 ms |
3456 KB |
Output is correct |
18 |
Correct |
7 ms |
3456 KB |
Output is correct |
19 |
Correct |
6 ms |
3456 KB |
Output is correct |
20 |
Correct |
6 ms |
3456 KB |
Output is correct |
21 |
Correct |
6 ms |
3456 KB |
Output is correct |
22 |
Correct |
6 ms |
3456 KB |
Output is correct |
23 |
Correct |
6 ms |
3456 KB |
Output is correct |
24 |
Correct |
6 ms |
3456 KB |
Output is correct |
25 |
Correct |
6 ms |
3456 KB |
Output is correct |
26 |
Correct |
6 ms |
3456 KB |
Output is correct |
27 |
Correct |
6 ms |
3456 KB |
Output is correct |
28 |
Incorrect |
6 ms |
3456 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
7040 KB |
Output is correct |
2 |
Incorrect |
26 ms |
7040 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
13688 KB |
Output is correct |
2 |
Correct |
57 ms |
13560 KB |
Output is correct |
3 |
Correct |
44 ms |
10360 KB |
Output is correct |
4 |
Correct |
14 ms |
4992 KB |
Output is correct |
5 |
Correct |
12 ms |
4352 KB |
Output is correct |
6 |
Correct |
18 ms |
5760 KB |
Output is correct |
7 |
Correct |
6 ms |
3456 KB |
Output is correct |
8 |
Correct |
30 ms |
7160 KB |
Output is correct |
9 |
Correct |
44 ms |
8568 KB |
Output is correct |
10 |
Correct |
8 ms |
3456 KB |
Output is correct |
11 |
Correct |
63 ms |
10488 KB |
Output is correct |
12 |
Correct |
73 ms |
11896 KB |
Output is correct |
13 |
Correct |
7 ms |
3584 KB |
Output is correct |
14 |
Correct |
7 ms |
3456 KB |
Output is correct |
15 |
Correct |
7 ms |
3584 KB |
Output is correct |
16 |
Correct |
7 ms |
3584 KB |
Output is correct |
17 |
Correct |
7 ms |
3456 KB |
Output is correct |
18 |
Correct |
8 ms |
3584 KB |
Output is correct |
19 |
Correct |
7 ms |
3584 KB |
Output is correct |
20 |
Incorrect |
7 ms |
3456 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
13688 KB |
Output is correct |
2 |
Correct |
57 ms |
13560 KB |
Output is correct |
3 |
Correct |
44 ms |
10360 KB |
Output is correct |
4 |
Correct |
14 ms |
4992 KB |
Output is correct |
5 |
Correct |
12 ms |
4352 KB |
Output is correct |
6 |
Correct |
18 ms |
5760 KB |
Output is correct |
7 |
Correct |
6 ms |
3456 KB |
Output is correct |
8 |
Correct |
30 ms |
7160 KB |
Output is correct |
9 |
Correct |
44 ms |
8568 KB |
Output is correct |
10 |
Correct |
8 ms |
3456 KB |
Output is correct |
11 |
Correct |
63 ms |
10488 KB |
Output is correct |
12 |
Correct |
73 ms |
11896 KB |
Output is correct |
13 |
Correct |
7 ms |
3584 KB |
Output is correct |
14 |
Correct |
6 ms |
3456 KB |
Output is correct |
15 |
Correct |
6 ms |
3456 KB |
Output is correct |
16 |
Correct |
7 ms |
3456 KB |
Output is correct |
17 |
Correct |
7 ms |
3456 KB |
Output is correct |
18 |
Correct |
7 ms |
3456 KB |
Output is correct |
19 |
Correct |
6 ms |
3456 KB |
Output is correct |
20 |
Correct |
6 ms |
3456 KB |
Output is correct |
21 |
Correct |
6 ms |
3456 KB |
Output is correct |
22 |
Correct |
6 ms |
3456 KB |
Output is correct |
23 |
Correct |
6 ms |
3456 KB |
Output is correct |
24 |
Correct |
6 ms |
3456 KB |
Output is correct |
25 |
Correct |
6 ms |
3456 KB |
Output is correct |
26 |
Correct |
6 ms |
3456 KB |
Output is correct |
27 |
Correct |
6 ms |
3456 KB |
Output is correct |
28 |
Incorrect |
6 ms |
3456 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |