#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; }
#define int long long
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);
}
}
signed travelTime(signed n, signed m, signed l, signed A[], signed B[], signed 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 |
63 ms |
13176 KB |
Output is correct |
2 |
Correct |
62 ms |
13048 KB |
Output is correct |
3 |
Correct |
40 ms |
9720 KB |
Output is correct |
4 |
Correct |
13 ms |
4864 KB |
Output is correct |
5 |
Correct |
12 ms |
4224 KB |
Output is correct |
6 |
Correct |
19 ms |
5504 KB |
Output is correct |
7 |
Correct |
6 ms |
3456 KB |
Output is correct |
8 |
Correct |
31 ms |
6904 KB |
Output is correct |
9 |
Correct |
43 ms |
8312 KB |
Output is correct |
10 |
Correct |
7 ms |
3584 KB |
Output is correct |
11 |
Correct |
56 ms |
9848 KB |
Output is correct |
12 |
Correct |
69 ms |
11440 KB |
Output is correct |
13 |
Correct |
7 ms |
3584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
13176 KB |
Output is correct |
2 |
Correct |
62 ms |
13048 KB |
Output is correct |
3 |
Correct |
40 ms |
9720 KB |
Output is correct |
4 |
Correct |
13 ms |
4864 KB |
Output is correct |
5 |
Correct |
12 ms |
4224 KB |
Output is correct |
6 |
Correct |
19 ms |
5504 KB |
Output is correct |
7 |
Correct |
6 ms |
3456 KB |
Output is correct |
8 |
Correct |
31 ms |
6904 KB |
Output is correct |
9 |
Correct |
43 ms |
8312 KB |
Output is correct |
10 |
Correct |
7 ms |
3584 KB |
Output is correct |
11 |
Correct |
56 ms |
9848 KB |
Output is correct |
12 |
Correct |
69 ms |
11440 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 |
6 ms |
3456 KB |
Output is correct |
18 |
Correct |
6 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 |
7 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 |
63 ms |
13176 KB |
Output is correct |
2 |
Correct |
62 ms |
13048 KB |
Output is correct |
3 |
Correct |
40 ms |
9720 KB |
Output is correct |
4 |
Correct |
13 ms |
4864 KB |
Output is correct |
5 |
Correct |
12 ms |
4224 KB |
Output is correct |
6 |
Correct |
19 ms |
5504 KB |
Output is correct |
7 |
Correct |
6 ms |
3456 KB |
Output is correct |
8 |
Correct |
31 ms |
6904 KB |
Output is correct |
9 |
Correct |
43 ms |
8312 KB |
Output is correct |
10 |
Correct |
7 ms |
3584 KB |
Output is correct |
11 |
Correct |
56 ms |
9848 KB |
Output is correct |
12 |
Correct |
69 ms |
11440 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 |
6 ms |
3456 KB |
Output is correct |
18 |
Correct |
6 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 |
7 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 |
25 ms |
7296 KB |
Output is correct |
2 |
Incorrect |
26 ms |
7296 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
13176 KB |
Output is correct |
2 |
Correct |
62 ms |
13048 KB |
Output is correct |
3 |
Correct |
40 ms |
9720 KB |
Output is correct |
4 |
Correct |
13 ms |
4864 KB |
Output is correct |
5 |
Correct |
12 ms |
4224 KB |
Output is correct |
6 |
Correct |
19 ms |
5504 KB |
Output is correct |
7 |
Correct |
6 ms |
3456 KB |
Output is correct |
8 |
Correct |
31 ms |
6904 KB |
Output is correct |
9 |
Correct |
43 ms |
8312 KB |
Output is correct |
10 |
Correct |
7 ms |
3584 KB |
Output is correct |
11 |
Correct |
56 ms |
9848 KB |
Output is correct |
12 |
Correct |
69 ms |
11440 KB |
Output is correct |
13 |
Correct |
7 ms |
3584 KB |
Output is correct |
14 |
Correct |
6 ms |
3456 KB |
Output is correct |
15 |
Correct |
8 ms |
3584 KB |
Output is correct |
16 |
Correct |
7 ms |
3584 KB |
Output is correct |
17 |
Correct |
6 ms |
3456 KB |
Output is correct |
18 |
Correct |
7 ms |
3584 KB |
Output is correct |
19 |
Correct |
8 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 |
63 ms |
13176 KB |
Output is correct |
2 |
Correct |
62 ms |
13048 KB |
Output is correct |
3 |
Correct |
40 ms |
9720 KB |
Output is correct |
4 |
Correct |
13 ms |
4864 KB |
Output is correct |
5 |
Correct |
12 ms |
4224 KB |
Output is correct |
6 |
Correct |
19 ms |
5504 KB |
Output is correct |
7 |
Correct |
6 ms |
3456 KB |
Output is correct |
8 |
Correct |
31 ms |
6904 KB |
Output is correct |
9 |
Correct |
43 ms |
8312 KB |
Output is correct |
10 |
Correct |
7 ms |
3584 KB |
Output is correct |
11 |
Correct |
56 ms |
9848 KB |
Output is correct |
12 |
Correct |
69 ms |
11440 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 |
6 ms |
3456 KB |
Output is correct |
18 |
Correct |
6 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 |
7 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 |
- |