#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
int cnt;
vector<int> v, u, vis;
vector<pii> a;
vector<vector<pii>> E;
int dfsv(int x, int p = -1) {
for (auto [i, w] : E[x]) {
if (i != p) v[x] = max(v[x], w + dfsv(i, x));
}
return v[x];
}
void dfsu(int x) {
vis[x] = cnt;
for (auto [i, w] : E[x]) {
if (!vis[i]) a.push_back({w + v[i], i});
}
sort(a.rbegin(), a.rend());
for (auto [i, w] : E[x]) {
if (!vis[i]) u[i] = max(u[x], (a[0].ss != i ? a[0].ff : (1 < (int)a.size() ? a[1].ff : 0))) + w;
}
a.clear();
for (auto [i, w] : E[x])
if (!vis[i]) dfsu(i);
}
int travelTime(int n, int m, int L, int A[], int B[], int T[]) {
E.assign(n, {});
for (int i = 0; i < m; i++) {
E[A[i]].push_back({B[i], T[i]});
E[B[i]].push_back({A[i], T[i]});
}
v.assign(n, 0);
u.assign(n, 0);
vis.assign(n, false);
for (int i = 0; i < n; i++) {
if (!vis[i]) {
cnt++;
dfsv(i); dfsu(i);
}
}
int mx = 0;
vector<int> mn(n, INT_MAX);
for (int i = 0; i < n; i++) {
mx = max({mx, v[i], u[i]});
mn[vis[i]] = min(mn[vis[i]], max(v[i], u[i]));
}
sort(mn.begin(), mn.end());
while (mn.back() == INT_MAX) mn.pop_back();
reverse(mn.begin(), mn.end());
mx = max(mx, mn[0]);
if (1 < (int)mn.size()) mx = max(mx, mn[0] + L + mn[1]);
if (2 < (int)mn.size()) mx = max(mx, mn[1] + (L << 1) + mn[2]);
return mx;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
13652 KB |
Output is correct |
2 |
Correct |
31 ms |
13320 KB |
Output is correct |
3 |
Correct |
22 ms |
11088 KB |
Output is correct |
4 |
Correct |
5 ms |
2172 KB |
Output is correct |
5 |
Correct |
4 ms |
1372 KB |
Output is correct |
6 |
Correct |
9 ms |
3164 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
16 ms |
5916 KB |
Output is correct |
9 |
Correct |
22 ms |
8796 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
32 ms |
9804 KB |
Output is correct |
12 |
Correct |
33 ms |
11348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
13652 KB |
Output is correct |
2 |
Correct |
31 ms |
13320 KB |
Output is correct |
3 |
Correct |
22 ms |
11088 KB |
Output is correct |
4 |
Correct |
5 ms |
2172 KB |
Output is correct |
5 |
Correct |
4 ms |
1372 KB |
Output is correct |
6 |
Correct |
9 ms |
3164 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
16 ms |
5916 KB |
Output is correct |
9 |
Correct |
22 ms |
8796 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
32 ms |
9804 KB |
Output is correct |
12 |
Correct |
33 ms |
11348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
6492 KB |
Output is correct |
2 |
Correct |
14 ms |
6328 KB |
Output is correct |
3 |
Correct |
15 ms |
6452 KB |
Output is correct |
4 |
Correct |
20 ms |
6360 KB |
Output is correct |
5 |
Correct |
17 ms |
6240 KB |
Output is correct |
6 |
Correct |
17 ms |
6716 KB |
Output is correct |
7 |
Correct |
14 ms |
6492 KB |
Output is correct |
8 |
Correct |
13 ms |
6224 KB |
Output is correct |
9 |
Correct |
13 ms |
6124 KB |
Output is correct |
10 |
Correct |
14 ms |
6760 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
4188 KB |
Output is correct |
13 |
Correct |
4 ms |
4188 KB |
Output is correct |
14 |
Correct |
4 ms |
4188 KB |
Output is correct |
15 |
Correct |
4 ms |
4188 KB |
Output is correct |
16 |
Correct |
3 ms |
4188 KB |
Output is correct |
17 |
Correct |
3 ms |
4184 KB |
Output is correct |
18 |
Correct |
4 ms |
4188 KB |
Output is correct |
19 |
Correct |
4 ms |
4188 KB |
Output is correct |
20 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
13652 KB |
Output is correct |
2 |
Correct |
31 ms |
13320 KB |
Output is correct |
3 |
Correct |
22 ms |
11088 KB |
Output is correct |
4 |
Correct |
5 ms |
2172 KB |
Output is correct |
5 |
Correct |
4 ms |
1372 KB |
Output is correct |
6 |
Correct |
9 ms |
3164 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
16 ms |
5916 KB |
Output is correct |
9 |
Correct |
22 ms |
8796 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
32 ms |
9804 KB |
Output is correct |
12 |
Correct |
33 ms |
11348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |