#include <bits/stdc++.h>
#include "dreaming.h"
#define ll long long
#define pii pair<int, int>
#define st first
#define nd second
using namespace std;
vector<pii> adj[100010];
vector<pii> connect;
bool visited[100010];
int max_dis, min_dis;
int u, v;
void dfs(int i, int prt, int dis) {
visited[i] = 1;
if (dis > max_dis) {
u = i;
max_dis = dis;
}
for (auto j : adj[i]) {
if (j.st == prt) continue;
dfs(j.st, i, dis + j.nd);
}
}
int dfs2(int i, int prt, int dis) {
if (i == v) {
min_dis = dis;
return 0;
}
for (auto j : adj[i]) {
if (j.st == prt) continue;
int k = dfs2(j.st, i, dis + j.nd);
if (k == -1) continue;
k += j.nd;
min_dis = min(max(dis, k), min_dis);
return k;
}
return -1;
}
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 mx1 = INT_MIN, mx2 = INT_MIN, mx3 = INT_MIN;
for (int i = 0; i < N; ++i) {
if (visited[i]) continue;
max_dis = 0, u = i;
dfs(i, -1, 0);
max_dis = 0, v = u;
dfs(v, -1, 0);
min_dis = INT_MAX;
dfs2(u, -1, 0);
if (min_dis > mx1) {
mx3 = mx2;
mx2 = mx1;
mx1 = min_dis;
}
else if (min_dis > mx2) {
mx3 = mx2;
mx2 = min_dis;
}
else if (min_dis > mx3) {
mx3 = min_dis;
}
}
if (N - M == 1) return mx1;
if (N - M == 2) return mx1 + mx2 + L;
else return max(mx1 + mx2 + L, mx2 + mx3 + 2*L);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
54 ms |
12308 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 |
54 ms |
12308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
5000 KB |
Output is correct |
2 |
Correct |
14 ms |
4992 KB |
Output is correct |
3 |
Correct |
16 ms |
5048 KB |
Output is correct |
4 |
Correct |
15 ms |
5068 KB |
Output is correct |
5 |
Correct |
15 ms |
5068 KB |
Output is correct |
6 |
Correct |
19 ms |
5212 KB |
Output is correct |
7 |
Correct |
16 ms |
5152 KB |
Output is correct |
8 |
Correct |
15 ms |
4940 KB |
Output is correct |
9 |
Correct |
15 ms |
5008 KB |
Output is correct |
10 |
Correct |
16 ms |
5044 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
3 ms |
2764 KB |
Output is correct |
13 |
Correct |
3 ms |
2764 KB |
Output is correct |
14 |
Correct |
3 ms |
2764 KB |
Output is correct |
15 |
Correct |
3 ms |
2764 KB |
Output is correct |
16 |
Correct |
3 ms |
2764 KB |
Output is correct |
17 |
Correct |
3 ms |
2636 KB |
Output is correct |
18 |
Correct |
4 ms |
2764 KB |
Output is correct |
19 |
Correct |
2 ms |
2764 KB |
Output is correct |
20 |
Correct |
1 ms |
2636 KB |
Output is correct |
21 |
Correct |
2 ms |
2636 KB |
Output is correct |
22 |
Correct |
1 ms |
2636 KB |
Output is correct |
23 |
Correct |
3 ms |
2764 KB |
Output is correct |
# |
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 |
54 ms |
12308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |