#include <bits/stdc++.h>
#include "dreaming.h"
#pragma GCC optimize("O3")
#define FOR(i, x, y) for (ll i = x; i < y; i++)
typedef long long ll;
using namespace std;
vector<pair<ll, ll>> graph[100001];
ll len, ans = 0, r[100001], indx = 0, cmp[100001];
pair<ll, ll> dp[100001];
bool visited[100001];
void ff(int node, int component, int parent = -1) {
visited[node] = true;
cmp[node] = component;
for (auto& i : graph[node]) {
if (i.first == parent) continue;
ff(i.first, component, node);
}
}
void dfs(ll node, ll parent = -1) {
int mx1 = 0, mx2 = 0;
for (auto& i : graph[node]) {
if (i.first == parent) continue;
dfs(i.first, node);
int e = dp[i.first].first + i.second;
if (e > mx1) {
mx2 = mx1;
mx1 = e;
} else if (e > mx2)
mx2 = e;
}
dp[node] = {mx1, mx2};
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
FOR(i, 0, M) {
graph[A[i]].push_back({B[i], T[i]});
graph[B[i]].push_back({A[i], T[i]});
}
FOR(i, 0, N) if (!visited[i]) ff(i, indx++);
fill(r, r + indx, INT_MAX);
FOR(i, 0, N) {
dfs(i);
r[cmp[i]] = min(r[cmp[i]], dp[i].first);
ans = max(ans, dp[i].first + dp[i].second);
}
sort(r, r + indx, greater<ll>());
ans = max(ans, max((indx > 2 ? r[1] + r[2] + 2 * L : 0),
max((indx > 1 ? r[0] + r[1] + L : 0), r[0])));
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1079 ms |
13604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1079 ms |
13604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1079 ms |
13604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
7832 KB |
Output is correct |
2 |
Correct |
32 ms |
7808 KB |
Output is correct |
3 |
Correct |
30 ms |
7928 KB |
Output is correct |
4 |
Correct |
30 ms |
7808 KB |
Output is correct |
5 |
Correct |
30 ms |
7800 KB |
Output is correct |
6 |
Correct |
31 ms |
8028 KB |
Output is correct |
7 |
Correct |
28 ms |
8056 KB |
Output is correct |
8 |
Correct |
28 ms |
7672 KB |
Output is correct |
9 |
Correct |
24 ms |
7680 KB |
Output is correct |
10 |
Correct |
27 ms |
8064 KB |
Output is correct |
11 |
Correct |
4 ms |
2688 KB |
Output is correct |
12 |
Correct |
8 ms |
5888 KB |
Output is correct |
13 |
Correct |
8 ms |
5888 KB |
Output is correct |
14 |
Correct |
8 ms |
5888 KB |
Output is correct |
15 |
Correct |
8 ms |
5888 KB |
Output is correct |
16 |
Correct |
8 ms |
6016 KB |
Output is correct |
17 |
Correct |
8 ms |
5860 KB |
Output is correct |
18 |
Correct |
9 ms |
5888 KB |
Output is correct |
19 |
Correct |
8 ms |
5888 KB |
Output is correct |
20 |
Correct |
4 ms |
2688 KB |
Output is correct |
21 |
Correct |
4 ms |
2688 KB |
Output is correct |
22 |
Correct |
4 ms |
2816 KB |
Output is correct |
23 |
Correct |
9 ms |
6016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1079 ms |
13604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1079 ms |
13604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |