#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) {
++A[i]; ++B[i];
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]; 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 = 1; d[a] = 0; dfs(a); d[a] = 0; dfs(a);
return d[a];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
12280 KB |
Output is correct |
2 |
Correct |
61 ms |
12280 KB |
Output is correct |
3 |
Correct |
43 ms |
9336 KB |
Output is correct |
4 |
Correct |
13 ms |
4736 KB |
Output is correct |
5 |
Incorrect |
13 ms |
4096 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
12280 KB |
Output is correct |
2 |
Correct |
61 ms |
12280 KB |
Output is correct |
3 |
Correct |
43 ms |
9336 KB |
Output is correct |
4 |
Correct |
13 ms |
4736 KB |
Output is correct |
5 |
Incorrect |
13 ms |
4096 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
12280 KB |
Output is correct |
2 |
Correct |
61 ms |
12280 KB |
Output is correct |
3 |
Correct |
43 ms |
9336 KB |
Output is correct |
4 |
Correct |
13 ms |
4736 KB |
Output is correct |
5 |
Incorrect |
13 ms |
4096 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
5700 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
12280 KB |
Output is correct |
2 |
Correct |
61 ms |
12280 KB |
Output is correct |
3 |
Correct |
43 ms |
9336 KB |
Output is correct |
4 |
Correct |
13 ms |
4736 KB |
Output is correct |
5 |
Incorrect |
13 ms |
4096 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
12280 KB |
Output is correct |
2 |
Correct |
61 ms |
12280 KB |
Output is correct |
3 |
Correct |
43 ms |
9336 KB |
Output is correct |
4 |
Correct |
13 ms |
4736 KB |
Output is correct |
5 |
Incorrect |
13 ms |
4096 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |