#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef complex<ld> point;
void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
cout << H << ' ';
debug_out(T...);
}
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
const int maxn = 1e5 + 10;
int n, m, l, h[2][maxn];
vector<pii> g[maxn];
vector<int> going, res;
bool vis[maxn];
void dfs(int v, int *h, int p = -1){
vis[v] = true;
going.push_back(v);
for (auto [u, w]: g[v]){
if (u != p){
h[u] = h[v] + w;
dfs(u, h, v);
}
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
n = N, m = M, l = L;
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]});
}
for (int i = 0; i < n; i++){
if (!vis[i]){
going.clear();
dfs(i, h[0]);
int q1 = i;
for (auto x: going){
if (h[0][x] > h[0][q1]) q1 = x;
}
going.clear();
dfs(q1, h[1]);
int q2 = i;
for (auto x: going){
if (h[1][x] > h[1][q2]) q2 = x;
}
going.clear();
h[0][q2] = 0;
dfs(q2, h[0]);
int ans = maxn;
for (auto x: going){
ans = min(ans, max(h[0][x], h[1][x]));
}
res.push_back(ans);
}
}
sort(all(res), greater<int>());
int ans = 0;
ans = max(ans, res[0]);
if (res.size() >= 2) ans = max(ans, res[0] + res[1] + l);
if (res.size() >= 3) ans = max(ans, res[1] + res[2] + 2 * l);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
33 ms |
13492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
33 ms |
13492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
6104 KB |
Output is correct |
2 |
Correct |
16 ms |
6192 KB |
Output is correct |
3 |
Correct |
15 ms |
6104 KB |
Output is correct |
4 |
Correct |
14 ms |
6124 KB |
Output is correct |
5 |
Correct |
15 ms |
6100 KB |
Output is correct |
6 |
Correct |
16 ms |
6616 KB |
Output is correct |
7 |
Correct |
16 ms |
6288 KB |
Output is correct |
8 |
Correct |
15 ms |
6104 KB |
Output is correct |
9 |
Correct |
14 ms |
6020 KB |
Output is correct |
10 |
Correct |
15 ms |
6192 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
12 |
Correct |
5 ms |
4048 KB |
Output is correct |
13 |
Correct |
5 ms |
4048 KB |
Output is correct |
14 |
Correct |
7 ms |
4048 KB |
Output is correct |
15 |
Correct |
5 ms |
4048 KB |
Output is correct |
16 |
Correct |
5 ms |
4048 KB |
Output is correct |
17 |
Correct |
5 ms |
3792 KB |
Output is correct |
18 |
Correct |
5 ms |
4048 KB |
Output is correct |
19 |
Correct |
5 ms |
4048 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
2644 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
5 ms |
4048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
33 ms |
13492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |