#include "dreaming.h"
#include <bits/stdc++.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;
bool visited[100001];
ll dfs(ll node, ll parent = -1) {
visited[node] = true;
for (auto& i : graph[node]) {
if (i.first == parent) continue;
return i.second + dfs(i.first, node);
}
return 0;
}
ll dfs2(ll node, ll parent = -1, ll left = 0) {
for (auto& i : graph[node]) {
if (i.first == parent) continue;
return min(max(left, len - left), dfs2(i.first, node, left + i.second));
}
return len;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
fill(visited, visited + N, false);
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 (graph[i].size() == 1 && !visited[i]) {
len = dfs(i);
ans = max(len, ans);
r[indx++] = dfs2(i);
}
}
return max(ans, r[0] + r[1] + L);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
9080 KB |
Output is correct |
2 |
Correct |
57 ms |
9080 KB |
Output is correct |
3 |
Correct |
34 ms |
6904 KB |
Output is correct |
4 |
Correct |
10 ms |
3584 KB |
Output is correct |
5 |
Correct |
9 ms |
3456 KB |
Output is correct |
6 |
Correct |
16 ms |
4224 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
28 ms |
5624 KB |
Output is correct |
9 |
Correct |
37 ms |
6392 KB |
Output is correct |
10 |
Correct |
4 ms |
2688 KB |
Output is correct |
11 |
Correct |
49 ms |
7672 KB |
Output is correct |
12 |
Correct |
55 ms |
8568 KB |
Output is correct |
13 |
Correct |
4 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
9080 KB |
Output is correct |
2 |
Correct |
57 ms |
9080 KB |
Output is correct |
3 |
Correct |
34 ms |
6904 KB |
Output is correct |
4 |
Correct |
10 ms |
3584 KB |
Output is correct |
5 |
Correct |
9 ms |
3456 KB |
Output is correct |
6 |
Correct |
16 ms |
4224 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
28 ms |
5624 KB |
Output is correct |
9 |
Correct |
37 ms |
6392 KB |
Output is correct |
10 |
Correct |
4 ms |
2688 KB |
Output is correct |
11 |
Correct |
49 ms |
7672 KB |
Output is correct |
12 |
Correct |
55 ms |
8568 KB |
Output is correct |
13 |
Correct |
4 ms |
2688 KB |
Output is correct |
14 |
Runtime error |
7 ms |
5120 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
9080 KB |
Output is correct |
2 |
Correct |
57 ms |
9080 KB |
Output is correct |
3 |
Correct |
34 ms |
6904 KB |
Output is correct |
4 |
Correct |
10 ms |
3584 KB |
Output is correct |
5 |
Correct |
9 ms |
3456 KB |
Output is correct |
6 |
Correct |
16 ms |
4224 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
28 ms |
5624 KB |
Output is correct |
9 |
Correct |
37 ms |
6392 KB |
Output is correct |
10 |
Correct |
4 ms |
2688 KB |
Output is correct |
11 |
Correct |
49 ms |
7672 KB |
Output is correct |
12 |
Correct |
55 ms |
8568 KB |
Output is correct |
13 |
Correct |
4 ms |
2688 KB |
Output is correct |
14 |
Runtime error |
7 ms |
5120 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
27 ms |
10104 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
9080 KB |
Output is correct |
2 |
Correct |
57 ms |
9080 KB |
Output is correct |
3 |
Correct |
34 ms |
6904 KB |
Output is correct |
4 |
Correct |
10 ms |
3584 KB |
Output is correct |
5 |
Correct |
9 ms |
3456 KB |
Output is correct |
6 |
Correct |
16 ms |
4224 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
28 ms |
5624 KB |
Output is correct |
9 |
Correct |
37 ms |
6392 KB |
Output is correct |
10 |
Correct |
4 ms |
2688 KB |
Output is correct |
11 |
Correct |
49 ms |
7672 KB |
Output is correct |
12 |
Correct |
55 ms |
8568 KB |
Output is correct |
13 |
Correct |
4 ms |
2688 KB |
Output is correct |
14 |
Runtime error |
6 ms |
5248 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
9080 KB |
Output is correct |
2 |
Correct |
57 ms |
9080 KB |
Output is correct |
3 |
Correct |
34 ms |
6904 KB |
Output is correct |
4 |
Correct |
10 ms |
3584 KB |
Output is correct |
5 |
Correct |
9 ms |
3456 KB |
Output is correct |
6 |
Correct |
16 ms |
4224 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
28 ms |
5624 KB |
Output is correct |
9 |
Correct |
37 ms |
6392 KB |
Output is correct |
10 |
Correct |
4 ms |
2688 KB |
Output is correct |
11 |
Correct |
49 ms |
7672 KB |
Output is correct |
12 |
Correct |
55 ms |
8568 KB |
Output is correct |
13 |
Correct |
4 ms |
2688 KB |
Output is correct |
14 |
Runtime error |
7 ms |
5120 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
15 |
Halted |
0 ms |
0 KB |
- |