#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int,int>>> gri;
vector<int> dis = {0,0};
vector<int> dep;
vector<int> used;
int jic = 0;
int y;
int dfs(int x, int p){
used[x] = 1;
int s = 0;
for(int i = 0; i < (int)gri[x].size(); ++i){
int z = 0;
if(gri[x][i].first != p)z = dfs(gri[x][i].first,x)+gri[x][i].second;
dep.push_back(z);
s+=z;
}
return s;
}
void find(int ind){
if(!gri[ind].size()){dis.push_back(0);return;}
dep.clear();
y = dfs(ind,ind);
jic = max(jic,y);
int best = INT_MAX;
for(int i = 0; i < (int)dep.size(); ++i){
best = min(best, max(y-dep[i],dep[i]));
}
dis.push_back(best);
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
used.resize(N,0);
gri.resize(N);
for(int i = 0; i < M; ++i){
gri[A[i]].push_back({B[i],T[i]});
gri[B[i]].push_back({A[i],T[i]});
}
for(int i = 0; i < N; ++i){
if(!used[i] && gri[i].size() == 1){
find(i);
}
}
sort(dis.rbegin(),dis.rend());
return max(jic,dis[0]+L+dis[1]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
16244 KB |
Output is correct |
2 |
Correct |
65 ms |
16372 KB |
Output is correct |
3 |
Correct |
39 ms |
10868 KB |
Output is correct |
4 |
Correct |
8 ms |
2816 KB |
Output is correct |
5 |
Correct |
6 ms |
1664 KB |
Output is correct |
6 |
Correct |
14 ms |
3968 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
26 ms |
6016 KB |
Output is correct |
9 |
Correct |
34 ms |
8312 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
54 ms |
10872 KB |
Output is correct |
12 |
Correct |
66 ms |
13764 KB |
Output is correct |
13 |
Correct |
1 ms |
416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
16244 KB |
Output is correct |
2 |
Correct |
65 ms |
16372 KB |
Output is correct |
3 |
Correct |
39 ms |
10868 KB |
Output is correct |
4 |
Correct |
8 ms |
2816 KB |
Output is correct |
5 |
Correct |
6 ms |
1664 KB |
Output is correct |
6 |
Correct |
14 ms |
3968 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
26 ms |
6016 KB |
Output is correct |
9 |
Correct |
34 ms |
8312 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
54 ms |
10872 KB |
Output is correct |
12 |
Correct |
66 ms |
13764 KB |
Output is correct |
13 |
Correct |
1 ms |
416 KB |
Output is correct |
14 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
16244 KB |
Output is correct |
2 |
Correct |
65 ms |
16372 KB |
Output is correct |
3 |
Correct |
39 ms |
10868 KB |
Output is correct |
4 |
Correct |
8 ms |
2816 KB |
Output is correct |
5 |
Correct |
6 ms |
1664 KB |
Output is correct |
6 |
Correct |
14 ms |
3968 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
26 ms |
6016 KB |
Output is correct |
9 |
Correct |
34 ms |
8312 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
54 ms |
10872 KB |
Output is correct |
12 |
Correct |
66 ms |
13764 KB |
Output is correct |
13 |
Correct |
1 ms |
416 KB |
Output is correct |
14 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
5880 KB |
Output is correct |
2 |
Incorrect |
29 ms |
6008 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
16244 KB |
Output is correct |
2 |
Correct |
65 ms |
16372 KB |
Output is correct |
3 |
Correct |
39 ms |
10868 KB |
Output is correct |
4 |
Correct |
8 ms |
2816 KB |
Output is correct |
5 |
Correct |
6 ms |
1664 KB |
Output is correct |
6 |
Correct |
14 ms |
3968 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
26 ms |
6016 KB |
Output is correct |
9 |
Correct |
34 ms |
8312 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
54 ms |
10872 KB |
Output is correct |
12 |
Correct |
66 ms |
13764 KB |
Output is correct |
13 |
Correct |
1 ms |
416 KB |
Output is correct |
14 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
16244 KB |
Output is correct |
2 |
Correct |
65 ms |
16372 KB |
Output is correct |
3 |
Correct |
39 ms |
10868 KB |
Output is correct |
4 |
Correct |
8 ms |
2816 KB |
Output is correct |
5 |
Correct |
6 ms |
1664 KB |
Output is correct |
6 |
Correct |
14 ms |
3968 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
26 ms |
6016 KB |
Output is correct |
9 |
Correct |
34 ms |
8312 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
54 ms |
10872 KB |
Output is correct |
12 |
Correct |
66 ms |
13764 KB |
Output is correct |
13 |
Correct |
1 ms |
416 KB |
Output is correct |
14 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |