#include "dreaming.h"
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
const int MAX_N = 1e5 + 5;
vii tree[MAX_N];
bitset<MAX_N> visited;
pii DfsFar(int node, int parent, int d) {
visited[node] = true;
pii p = {d, node};
for (auto [neighbor, w] : tree[node]) {
if (neighbor != parent) {
chkmax(p, DfsFar(neighbor, node, d + w));
}
}
return p;
}
bool DfsPath(int node, int parent, int end, vii &path) {
if (node == end) {
path.push_back({node, 0});
return true;
}
for (auto [neighbor, w] : tree[node]) {
if (neighbor != parent && DfsPath(neighbor, node, end, path)) {
path.push_back({node, w});
return true;
}
}
}
int FindRadius(int node) {
int v = DfsFar(node, -1, 0).y;
auto [diameter, u] = DfsFar(v, -1, 0);
int x = diameter;
int dist = 0;
vii path;
DfsPath(v, -1, u, path);
for (auto [node, w] : path) {
chkmin(x, max(dist, diameter - dist));
dist += w;
}
return x;
}
int travelTime(int n, int m, int l, int a[], int b[], int t[]) {
for (int i = 0; i < m; i++) {
tree[a[i]].push_back({b[i], t[i]});
tree[b[i]].push_back({a[i], t[i]});
}
int ans = 0;
for (int i = 0; i < n; i++) {
if (!visited[i]) {
ans += FindRadius(i) + l;
}
}
return ans - l;
}
Compilation message
dreaming.cpp: In function 'bool DfsPath(int, int, int, vii&)':
dreaming.cpp:43:1: warning: control reaches end of non-void function [-Wreturn-type]
43 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
47 ms |
16084 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
34 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
47 ms |
16084 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
23 ms |
5396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
34 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
47 ms |
16084 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |