#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
ostream& operator<<(ostream &out, string str) {
for(char c : str) out << c;
return out;
}
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
return out << "(" << p.ST << ", " << p.ND << ")";
}
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
out << "{";
for(auto it = a.begin(); it != a.end(); it = next(it))
out << (it != a.begin() ? ", " : "") << *it;
return out << "}";
}
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
cerr << a << ", ";
dump(x...);
}
#ifdef DEBUG
# define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
# define debug(...) false
#endif
template<class T> int size(T && a) { return (int) a.size(); }
using LL = long long;
using PII = pair<int, int>;
#include "dreaming.h"
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
vector<vector<PII>> adj(N);
REP(i, M) {
adj[A[i]].emplace_back(B[i], T[i]);
adj[B[i]].emplace_back(A[i], T[i]);
}
vector<int> dst(N, -1), component;
function<void(int, bool)> get_dst = [&](int v, bool get_comp) {
if(get_comp) component.emplace_back(v);
if(dst[v] == -1) dst[v] = 0;
for(auto &[u, w] : adj[v]) {
if(dst[u] == -1) {
dst[u] = dst[v] + w;
get_dst(u, get_comp);
}
}
};
auto clear_dst = [&]() {
for(int i : component)
dst[i] = -1;
};
int inf = (int) 1e9;
vector<int> cen(N), q = {-inf, -inf};
REP(i, N) if(dst[i] == -1) {
auto get_far = [&](int x) {
clear_dst();
get_dst(x, false);
PII best = {-1, -1};
for(int j : component)
best = max(best, {dst[j], j});
return best.ND;
};
auto update_cen = [&]() {
int ret = inf;
for(int j : component) {
cen[j] = max(cen[j], dst[j]);
ret = min(ret, cen[j]);
}
return ret;
};
get_dst(i, true);
int a = get_far(i);
int b = get_far(a);
update_cen();
get_far(b);
q.emplace_back(update_cen());
component.clear();
}
sort(q.rbegin(), q.rend());
return max({q[0], q[0] + L + q[1], q[1] + 2 * L + q[2]});
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
87 ms |
17392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
87 ms |
17392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
87 ms |
17392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
6400 KB |
Output is correct |
2 |
Correct |
38 ms |
6392 KB |
Output is correct |
3 |
Correct |
39 ms |
6392 KB |
Output is correct |
4 |
Correct |
37 ms |
6392 KB |
Output is correct |
5 |
Correct |
37 ms |
6400 KB |
Output is correct |
6 |
Correct |
43 ms |
7032 KB |
Output is correct |
7 |
Correct |
39 ms |
6656 KB |
Output is correct |
8 |
Correct |
39 ms |
6264 KB |
Output is correct |
9 |
Correct |
36 ms |
6272 KB |
Output is correct |
10 |
Correct |
37 ms |
6656 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
17 ms |
4092 KB |
Output is correct |
13 |
Correct |
15 ms |
4220 KB |
Output is correct |
14 |
Correct |
15 ms |
4220 KB |
Output is correct |
15 |
Correct |
15 ms |
4220 KB |
Output is correct |
16 |
Correct |
14 ms |
4092 KB |
Output is correct |
17 |
Correct |
14 ms |
4124 KB |
Output is correct |
18 |
Correct |
26 ms |
4220 KB |
Output is correct |
19 |
Correct |
14 ms |
4220 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
512 KB |
Output is correct |
23 |
Correct |
14 ms |
4092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
87 ms |
17392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
87 ms |
17392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |