#include <bits/stdc++.h>
using namespace std;
#define sp << ' ' <<
#define nl << '\n'
#include "dreaming.h"
const int MAXN = 1e5, INF = 2e9;
vector<array<int, 2>> g[MAXN];
int a[MAXN], b, x, y;
bitset<MAXN> vis;
void dfs(int u, int d, int p = -1){
vis[u] = 1;
a[u] = max(a[u], d);
if(d > x) x = d, y = u;
if(d < 0) b = min(b, a[u]);
for(auto &e : g[u]) if(e[0] != p) dfs(e[0], d < 0 ? d : d + e[1], u);
}
int travelTime(int n, int m, int L, int A[], int B[], int T[]){
for(int i=0; i<m; ++i){
g[A[i]].push_back({B[i], T[i]});
g[B[i]].push_back({A[i], T[i]});
}
priority_queue<int> q;
for(int i=0; i<n; ++i){
if(vis[i]) continue;
x = y = -1, b = INF;
dfs(i, 0), dfs(y, 0), dfs(y, 0);
dfs(i, -1);
q.push(-b);
while(q.size() > 3) q.pop();
}
int a3 = -q.top(); q.pop();
int a2 = -q.top(); q.pop();
if(n < 3) return L + a2 + a3;
int a1 = -q.top(); q.pop();
return max(a1 + a2 + L, a2 + a3 + L + L);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
57 ms |
11848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
57 ms |
11848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
5692 KB |
Output is correct |
2 |
Correct |
22 ms |
5760 KB |
Output is correct |
3 |
Correct |
21 ms |
5708 KB |
Output is correct |
4 |
Correct |
22 ms |
5728 KB |
Output is correct |
5 |
Correct |
22 ms |
5668 KB |
Output is correct |
6 |
Correct |
25 ms |
5968 KB |
Output is correct |
7 |
Correct |
25 ms |
5844 KB |
Output is correct |
8 |
Correct |
28 ms |
5708 KB |
Output is correct |
9 |
Correct |
26 ms |
5700 KB |
Output is correct |
10 |
Correct |
25 ms |
5888 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
7 ms |
3020 KB |
Output is correct |
13 |
Correct |
6 ms |
3020 KB |
Output is correct |
14 |
Correct |
6 ms |
3020 KB |
Output is correct |
15 |
Correct |
6 ms |
3020 KB |
Output is correct |
16 |
Correct |
6 ms |
3020 KB |
Output is correct |
17 |
Correct |
6 ms |
3020 KB |
Output is correct |
18 |
Correct |
7 ms |
3048 KB |
Output is correct |
19 |
Correct |
6 ms |
3020 KB |
Output is correct |
20 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
57 ms |
11848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |