#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, c[N], e[N];
void dfs(int u, int p = 0) {
if (d[u] > d[a]) a = u;
::p[u] = p;
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 cmp = 0;
rep(u, 0, n) {
if (!p[u]) continue;
a = u; d[a] = 0; dfs(u); d[a] = 0; dfs(a);
e[cmp] = d[a]; c[cmp] = a;
for (int v = a; p[v] != -1; v = p[v])
if (ckmin(e[cmp], max(d[a] - d[v], d[v])))
c[cmp] = v;
++cmp;
}
int x = 0;
rep(i, 0, cmp) if (e[i] > e[x]) x = i;
rep(i, 0, cmp) {
if (x == i) continue;
g[c[x]].eb(c[i], l);
g[c[i]].eb(c[x], l);
}
a = 0; d[a] = 0; dfs(a); d[a] = 0; dfs(a);
return d[a];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
12408 KB |
Output is correct |
2 |
Correct |
60 ms |
12280 KB |
Output is correct |
3 |
Correct |
43 ms |
9216 KB |
Output is correct |
4 |
Correct |
13 ms |
4736 KB |
Output is correct |
5 |
Incorrect |
11 ms |
4096 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
12408 KB |
Output is correct |
2 |
Correct |
60 ms |
12280 KB |
Output is correct |
3 |
Correct |
43 ms |
9216 KB |
Output is correct |
4 |
Correct |
13 ms |
4736 KB |
Output is correct |
5 |
Incorrect |
11 ms |
4096 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
12408 KB |
Output is correct |
2 |
Correct |
60 ms |
12280 KB |
Output is correct |
3 |
Correct |
43 ms |
9216 KB |
Output is correct |
4 |
Correct |
13 ms |
4736 KB |
Output is correct |
5 |
Incorrect |
11 ms |
4096 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
5760 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
12408 KB |
Output is correct |
2 |
Correct |
60 ms |
12280 KB |
Output is correct |
3 |
Correct |
43 ms |
9216 KB |
Output is correct |
4 |
Correct |
13 ms |
4736 KB |
Output is correct |
5 |
Incorrect |
11 ms |
4096 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
12408 KB |
Output is correct |
2 |
Correct |
60 ms |
12280 KB |
Output is correct |
3 |
Correct |
43 ms |
9216 KB |
Output is correct |
4 |
Correct |
13 ms |
4736 KB |
Output is correct |
5 |
Incorrect |
11 ms |
4096 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |