#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(q.empty()) 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 |
52 ms |
11136 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 |
52 ms |
11136 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
5344 KB |
Output is correct |
2 |
Correct |
23 ms |
5324 KB |
Output is correct |
3 |
Correct |
22 ms |
5352 KB |
Output is correct |
4 |
Correct |
22 ms |
5268 KB |
Output is correct |
5 |
Correct |
22 ms |
5248 KB |
Output is correct |
6 |
Correct |
23 ms |
5468 KB |
Output is correct |
7 |
Correct |
23 ms |
5452 KB |
Output is correct |
8 |
Correct |
22 ms |
5196 KB |
Output is correct |
9 |
Correct |
21 ms |
5284 KB |
Output is correct |
10 |
Correct |
28 ms |
5360 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
6 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 |
7 ms |
3020 KB |
Output is correct |
18 |
Correct |
7 ms |
3104 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 |
52 ms |
11136 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |