#include<bits/stdc++.h>
#include "dreaming.h"
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
#define fi first
#define se second
vector<int> Tree;
ll d[N];
bool used[N];
int pa[N];
vector<pair<int, int>> g[N];
void dfs (int u, int p) {
Tree.push_back(u);
used[u] = 1;
pa[u] = p;
for (auto& e : g[u]) {
int v = e.fi;
int w = e.se;
if (v != p) {
d[v] = d[u] + w;
dfs(v, u);
}
}
}
// int travelTime (int n, int m, int L, vector<int> A, vector<int> B, vector<int> T) {
int travelTime (int n, int m, int L, int A[], int B[], int T[]) {
for (int i = 0; i < m; i++) {
g[A[i]].push_back({B[i], T[i]});
g[B[i]].push_back({A[i], T[i]});
}
int pre = -1;
for (int i = 0; i < n; i++) {
if (!used[i]) {
dfs(i, -1);
int v = i;
for (auto& j : Tree) if (d[j] > d[v]) {
v = j;
d[j] = pa[j] = 0;
}
Tree.clear();
dfs(v, -1);
for (auto &j : Tree) if (d[j] > d[v]) v = j;
int u = v;
int x = v;
while (u != -1) {
if (abs(2 * d[u] - d[v]) < abs(2 * d[x] - d[v])) {
x = u;
}
u = pa[u];
}
if (pre != -1) {
g[pre].push_back({x, L});
g[x].push_back({pre, L});
}
pre = x;
for (auto &j : Tree) {
d[j] = pa[j] = 0;
}
Tree.clear();
}
}
dfs(0, -1);
int v = 0;
for (int i = 0; i < n; i++) if (d[i] > d[v]) v = i, d[i] = 0;
dfs(v, -1);
for (int i = 0; i < n; i++) if (d[i] > d[v]) v = i;
return d[v];
}
// signed main() {
// ios_base::sync_with_stdio(0);
// cin.tie(0);
//
// cout << travelTime(12, 8, 2, {0,8,2,5,5,1,1,10}, {8,2,7,11,1,3,9,6}, {4,2,4,3,7,1,5,3});
//
// return 0;
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
61 ms |
15732 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2664 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
61 ms |
15732 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
34 ms |
13140 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2664 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
61 ms |
15732 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |