#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;
vector< pair<int,int> > edg[100005];
int vis[100005];
int bck[100005], dis[100005];
int mxdis = -1, mxdisnode = 0;
vector<int> v;
void dfs(int x, int p, int d) {
vis[x] = 1;
if(d>mxdis) {
mxdis = d; mxdisnode = x;
}
for(auto i:edg[x]) {
if(i.first!=p) {
bck[i.first] = x;
dis[i.first] = i.second;
dfs(i.first, x, d+i.second);
}
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for(int i=0; i<M; i++) {
edg[A[i]].push_back({B[i],T[i]});
edg[B[i]].push_back({A[i],T[i]});
}
int ans = 0;
for(int i=0; i<N; i++) {
if(vis[i]==0) {
mxdis = -1;
dfs(i, -1, 0);
mxdis = -1;
int orig = mxdisnode;
dfs(orig, -1, 0);
int ptr = mxdisnode;
int cendis = mxdis, cnt = 0;
while(ptr != orig) {
cnt += dis[ptr];
ptr = bck[ptr];
if(max(cnt, mxdis - cnt) < cendis) {
cendis = max(cnt, mxdis - cnt);
}
}
v.push_back(cendis);
}
}
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
ans = v[0];
if(v.size() >= 2) {
ans = max(ans, v[0] + v[1] + L);
}
if(v.size() >= 3) {
ans = max(ans, v[1] + v[2] + L*2);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
13260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
13260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
6444 KB |
Output is correct |
2 |
Correct |
18 ms |
6484 KB |
Output is correct |
3 |
Correct |
18 ms |
6904 KB |
Output is correct |
4 |
Correct |
21 ms |
6868 KB |
Output is correct |
5 |
Correct |
26 ms |
6884 KB |
Output is correct |
6 |
Correct |
21 ms |
7384 KB |
Output is correct |
7 |
Correct |
20 ms |
7036 KB |
Output is correct |
8 |
Correct |
19 ms |
6752 KB |
Output is correct |
9 |
Correct |
19 ms |
6744 KB |
Output is correct |
10 |
Correct |
24 ms |
6928 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
5 ms |
4432 KB |
Output is correct |
13 |
Correct |
5 ms |
4432 KB |
Output is correct |
14 |
Correct |
5 ms |
4432 KB |
Output is correct |
15 |
Correct |
5 ms |
4432 KB |
Output is correct |
16 |
Correct |
6 ms |
4452 KB |
Output is correct |
17 |
Correct |
5 ms |
4048 KB |
Output is correct |
18 |
Correct |
5 ms |
4432 KB |
Output is correct |
19 |
Correct |
5 ms |
4432 KB |
Output is correct |
20 |
Correct |
2 ms |
2660 KB |
Output is correct |
21 |
Correct |
2 ms |
2644 KB |
Output is correct |
22 |
Correct |
2 ms |
2704 KB |
Output is correct |
23 |
Correct |
5 ms |
4452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
13260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |