#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
#define pii pair<int, int>
#define f first
#define s second
const int mx = 1e5 + 5, inf = 1e9;
vector<pii> adj[mx]; pii in[mx]; bool vis[mx];
void comb(pii &p, int x){
if (x > p.f) p.s = p.f, p.f = x;
else if (x > p.s) p.s = x;
}
void dfs1(int i, int p){
vis[i] = 1;
for (auto [x, w] : adj[i]) if (x != p){
dfs1(x, i);
comb(in[i], in[x].f + w);
}
}
void dfs2(int i, int p, int pout, int &mnD){
mnD = min(mnD, max(pout, in[i].f));
for (auto [x, w] : adj[i]) if (x != p){
int sib = (in[i].f == in[x].f + w) ? in[i].s : in[i].f;
int out = max(sib + w, pout);
dfs2(x, i, out, mnD);
}
}
int travelTime(int n, int m, int l, int A[], int B[], int T[]){
for (int i = 0; i < m; i++){
adj[A[i]].push_back({B[i], T[i]});
adj[B[i]].push_back({A[i], T[i]});
}
int mn = 1e9; pii mxFar = {-l, -l};
for (int i = 0; i < n; i++) if (!vis[i]){
int mnD = 1e9; dfs1(i, 0); dfs2(i, 0, 0, mnD);
mn = min(mn, mnD); comb(mxFar, mnD);
}
if (n == 1) return 0;
if (n == 2) return m ? T[0] : l;
return mn + mxFar.f + mxFar.s + 2 * l;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
55 ms |
11224 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
55 ms |
11224 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
5696 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
55 ms |
11224 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |