#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 = -1, r[2], 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>());
// FOR(i, 0, indx) cout << r[i] << ' ';
// cout << '\n';
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;
}
Compilation message
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:55:46: warning: array subscript is above array bounds [-Warray-bounds]
ans = max(ans, max((indx > 2 ? r[1] + r[2] + 2 * L : 0),
~~~^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1082 ms |
13752 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1082 ms |
13752 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1082 ms |
13752 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
29 ms |
12132 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1082 ms |
13752 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1082 ms |
13752 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |