#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
#define fi first
#define se second
#define INF (int)(1e9)
vector<vector<pair<int,int> > > vec;
bool vis[100005];
int maxi=0,a,idx=0;
vector<pair<int,int> > tree_d;
pair<int,int> p[100005],center[100005];
//vector<int> nodes;
void dfs(int node,int d){
//nodes.push_back(node);
if(d>maxi)
a=node,maxi=d;
vis[node]=1;
for(auto child:vec[node])
if(child.fi!=p[node].fi){
vis[child.fi]=1;
p[child.fi]={node,child.se};
dfs(child.fi,d+child.se);
}
}
pair<int,int> findCenter(int node){
maxi=0;
dfs(node,0);
memset(p,-1,sizeof p);
int B=a,sum=0,mini=INF,c=node,sh=INF;
maxi=0;
dfs(B,0);
for(;a!=-1;sum+=p[a].se,a=p[a].fi){
if(abs(maxi/2-sum)<mini)
mini=abs(maxi/2-sum),c=a,sh=sum;
}
memset(p,-1,sizeof p);
tree_d.push_back({maxi,idx});
return {c,max(maxi-sh,0)};
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
vec.resize(N+2);
for (int i = 0; i < M; ++i)
{
vec[A[i]].push_back({B[i],T[i]});
vec[B[i]].push_back({A[i],T[i]});
}
for (int i = 0; i < N; ++i)
if(!vis[i])
center[idx++]=findCenter(i);
sort(tree_d.begin(),tree_d.end(),greater<pair<int,int> >());
for (int i = 1; i < idx; ++i)
{
//cout<<center[tree_d[i].se].fi<<" "<<center[tree_d[0].se].fi<<"\n";
vec[center[tree_d[i].se].fi].push_back({center[tree_d[0].se].fi,L});
vec[center[tree_d[0].se].fi].push_back({center[tree_d[i].se].fi,L});
}
maxi=0;
memset(p,-1,sizeof p);
dfs(0,0);
//nodes.clear();
int b=a;
memset(p,-1,sizeof p);
maxi=0;
dfs(b,0);
return maxi;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
11512 KB |
Output is correct |
2 |
Correct |
71 ms |
11584 KB |
Output is correct |
3 |
Correct |
48 ms |
7928 KB |
Output is correct |
4 |
Correct |
11 ms |
2688 KB |
Output is correct |
5 |
Correct |
9 ms |
2048 KB |
Output is correct |
6 |
Correct |
17 ms |
3456 KB |
Output is correct |
7 |
Correct |
3 ms |
1152 KB |
Output is correct |
8 |
Correct |
32 ms |
4984 KB |
Output is correct |
9 |
Correct |
40 ms |
6392 KB |
Output is correct |
10 |
Correct |
3 ms |
1152 KB |
Output is correct |
11 |
Correct |
57 ms |
8056 KB |
Output is correct |
12 |
Correct |
97 ms |
9848 KB |
Output is correct |
13 |
Correct |
3 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
11512 KB |
Output is correct |
2 |
Correct |
71 ms |
11584 KB |
Output is correct |
3 |
Correct |
48 ms |
7928 KB |
Output is correct |
4 |
Correct |
11 ms |
2688 KB |
Output is correct |
5 |
Correct |
9 ms |
2048 KB |
Output is correct |
6 |
Correct |
17 ms |
3456 KB |
Output is correct |
7 |
Correct |
3 ms |
1152 KB |
Output is correct |
8 |
Correct |
32 ms |
4984 KB |
Output is correct |
9 |
Correct |
40 ms |
6392 KB |
Output is correct |
10 |
Correct |
3 ms |
1152 KB |
Output is correct |
11 |
Correct |
57 ms |
8056 KB |
Output is correct |
12 |
Correct |
97 ms |
9848 KB |
Output is correct |
13 |
Correct |
3 ms |
1152 KB |
Output is correct |
14 |
Correct |
3 ms |
1152 KB |
Output is correct |
15 |
Correct |
3 ms |
1152 KB |
Output is correct |
16 |
Correct |
3 ms |
1152 KB |
Output is correct |
17 |
Correct |
3 ms |
1152 KB |
Output is correct |
18 |
Correct |
3 ms |
1152 KB |
Output is correct |
19 |
Correct |
3 ms |
1152 KB |
Output is correct |
20 |
Correct |
3 ms |
1152 KB |
Output is correct |
21 |
Correct |
3 ms |
1152 KB |
Output is correct |
22 |
Correct |
3 ms |
1152 KB |
Output is correct |
23 |
Correct |
3 ms |
1152 KB |
Output is correct |
24 |
Correct |
3 ms |
1152 KB |
Output is correct |
25 |
Correct |
2 ms |
1152 KB |
Output is correct |
26 |
Correct |
3 ms |
1152 KB |
Output is correct |
27 |
Correct |
3 ms |
1152 KB |
Output is correct |
28 |
Correct |
3 ms |
1152 KB |
Output is correct |
29 |
Correct |
3 ms |
1152 KB |
Output is correct |
30 |
Correct |
3 ms |
1152 KB |
Output is correct |
31 |
Correct |
2 ms |
1152 KB |
Output is correct |
32 |
Correct |
3 ms |
1152 KB |
Output is correct |
33 |
Correct |
3 ms |
1152 KB |
Output is correct |
34 |
Correct |
2 ms |
1152 KB |
Output is correct |
35 |
Correct |
3 ms |
1152 KB |
Output is correct |
36 |
Correct |
3 ms |
1152 KB |
Output is correct |
37 |
Correct |
3 ms |
1152 KB |
Output is correct |
38 |
Correct |
3 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
11512 KB |
Output is correct |
2 |
Correct |
71 ms |
11584 KB |
Output is correct |
3 |
Correct |
48 ms |
7928 KB |
Output is correct |
4 |
Correct |
11 ms |
2688 KB |
Output is correct |
5 |
Correct |
9 ms |
2048 KB |
Output is correct |
6 |
Correct |
17 ms |
3456 KB |
Output is correct |
7 |
Correct |
3 ms |
1152 KB |
Output is correct |
8 |
Correct |
32 ms |
4984 KB |
Output is correct |
9 |
Correct |
40 ms |
6392 KB |
Output is correct |
10 |
Correct |
3 ms |
1152 KB |
Output is correct |
11 |
Correct |
57 ms |
8056 KB |
Output is correct |
12 |
Correct |
97 ms |
9848 KB |
Output is correct |
13 |
Correct |
3 ms |
1152 KB |
Output is correct |
14 |
Correct |
3 ms |
1152 KB |
Output is correct |
15 |
Correct |
3 ms |
1152 KB |
Output is correct |
16 |
Correct |
3 ms |
1152 KB |
Output is correct |
17 |
Correct |
3 ms |
1152 KB |
Output is correct |
18 |
Correct |
3 ms |
1152 KB |
Output is correct |
19 |
Correct |
3 ms |
1152 KB |
Output is correct |
20 |
Correct |
3 ms |
1152 KB |
Output is correct |
21 |
Correct |
3 ms |
1152 KB |
Output is correct |
22 |
Correct |
3 ms |
1152 KB |
Output is correct |
23 |
Correct |
3 ms |
1152 KB |
Output is correct |
24 |
Correct |
3 ms |
1152 KB |
Output is correct |
25 |
Correct |
2 ms |
1152 KB |
Output is correct |
26 |
Correct |
3 ms |
1152 KB |
Output is correct |
27 |
Correct |
3 ms |
1152 KB |
Output is correct |
28 |
Correct |
3 ms |
1152 KB |
Output is correct |
29 |
Correct |
3 ms |
1152 KB |
Output is correct |
30 |
Correct |
3 ms |
1152 KB |
Output is correct |
31 |
Correct |
2 ms |
1152 KB |
Output is correct |
32 |
Correct |
3 ms |
1152 KB |
Output is correct |
33 |
Correct |
3 ms |
1152 KB |
Output is correct |
34 |
Correct |
2 ms |
1152 KB |
Output is correct |
35 |
Correct |
3 ms |
1152 KB |
Output is correct |
36 |
Correct |
3 ms |
1152 KB |
Output is correct |
37 |
Correct |
3 ms |
1152 KB |
Output is correct |
38 |
Correct |
3 ms |
1152 KB |
Output is correct |
39 |
Correct |
97 ms |
11640 KB |
Output is correct |
40 |
Correct |
69 ms |
11512 KB |
Output is correct |
41 |
Correct |
44 ms |
7928 KB |
Output is correct |
42 |
Correct |
11 ms |
2688 KB |
Output is correct |
43 |
Correct |
3 ms |
1152 KB |
Output is correct |
44 |
Correct |
3 ms |
1152 KB |
Output is correct |
45 |
Correct |
3 ms |
1152 KB |
Output is correct |
46 |
Correct |
3 ms |
1152 KB |
Output is correct |
47 |
Correct |
3 ms |
1152 KB |
Output is correct |
48 |
Correct |
2 ms |
1152 KB |
Output is correct |
49 |
Correct |
3 ms |
1152 KB |
Output is correct |
50 |
Correct |
3 ms |
1152 KB |
Output is correct |
51 |
Correct |
3 ms |
1152 KB |
Output is correct |
52 |
Correct |
3 ms |
1152 KB |
Output is correct |
53 |
Correct |
2 ms |
1152 KB |
Output is correct |
54 |
Correct |
4 ms |
1152 KB |
Output is correct |
55 |
Correct |
2 ms |
1152 KB |
Output is correct |
56 |
Correct |
3 ms |
1152 KB |
Output is correct |
57 |
Correct |
91 ms |
8760 KB |
Output is correct |
58 |
Correct |
87 ms |
8700 KB |
Output is correct |
59 |
Correct |
122 ms |
8696 KB |
Output is correct |
60 |
Correct |
80 ms |
8696 KB |
Output is correct |
61 |
Correct |
84 ms |
8568 KB |
Output is correct |
62 |
Correct |
69 ms |
8568 KB |
Output is correct |
63 |
Correct |
72 ms |
8440 KB |
Output is correct |
64 |
Runtime error |
76 ms |
16632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
65 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
24 ms |
11136 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
11512 KB |
Output is correct |
2 |
Correct |
71 ms |
11584 KB |
Output is correct |
3 |
Correct |
48 ms |
7928 KB |
Output is correct |
4 |
Correct |
11 ms |
2688 KB |
Output is correct |
5 |
Correct |
9 ms |
2048 KB |
Output is correct |
6 |
Correct |
17 ms |
3456 KB |
Output is correct |
7 |
Correct |
3 ms |
1152 KB |
Output is correct |
8 |
Correct |
32 ms |
4984 KB |
Output is correct |
9 |
Correct |
40 ms |
6392 KB |
Output is correct |
10 |
Correct |
3 ms |
1152 KB |
Output is correct |
11 |
Correct |
57 ms |
8056 KB |
Output is correct |
12 |
Correct |
97 ms |
9848 KB |
Output is correct |
13 |
Correct |
3 ms |
1152 KB |
Output is correct |
14 |
Runtime error |
8 ms |
2304 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
11512 KB |
Output is correct |
2 |
Correct |
71 ms |
11584 KB |
Output is correct |
3 |
Correct |
48 ms |
7928 KB |
Output is correct |
4 |
Correct |
11 ms |
2688 KB |
Output is correct |
5 |
Correct |
9 ms |
2048 KB |
Output is correct |
6 |
Correct |
17 ms |
3456 KB |
Output is correct |
7 |
Correct |
3 ms |
1152 KB |
Output is correct |
8 |
Correct |
32 ms |
4984 KB |
Output is correct |
9 |
Correct |
40 ms |
6392 KB |
Output is correct |
10 |
Correct |
3 ms |
1152 KB |
Output is correct |
11 |
Correct |
57 ms |
8056 KB |
Output is correct |
12 |
Correct |
97 ms |
9848 KB |
Output is correct |
13 |
Correct |
3 ms |
1152 KB |
Output is correct |
14 |
Correct |
3 ms |
1152 KB |
Output is correct |
15 |
Correct |
3 ms |
1152 KB |
Output is correct |
16 |
Correct |
3 ms |
1152 KB |
Output is correct |
17 |
Correct |
3 ms |
1152 KB |
Output is correct |
18 |
Correct |
3 ms |
1152 KB |
Output is correct |
19 |
Correct |
3 ms |
1152 KB |
Output is correct |
20 |
Correct |
3 ms |
1152 KB |
Output is correct |
21 |
Correct |
3 ms |
1152 KB |
Output is correct |
22 |
Correct |
3 ms |
1152 KB |
Output is correct |
23 |
Correct |
3 ms |
1152 KB |
Output is correct |
24 |
Correct |
3 ms |
1152 KB |
Output is correct |
25 |
Correct |
2 ms |
1152 KB |
Output is correct |
26 |
Correct |
3 ms |
1152 KB |
Output is correct |
27 |
Correct |
3 ms |
1152 KB |
Output is correct |
28 |
Correct |
3 ms |
1152 KB |
Output is correct |
29 |
Correct |
3 ms |
1152 KB |
Output is correct |
30 |
Correct |
3 ms |
1152 KB |
Output is correct |
31 |
Correct |
2 ms |
1152 KB |
Output is correct |
32 |
Correct |
3 ms |
1152 KB |
Output is correct |
33 |
Correct |
3 ms |
1152 KB |
Output is correct |
34 |
Correct |
2 ms |
1152 KB |
Output is correct |
35 |
Correct |
3 ms |
1152 KB |
Output is correct |
36 |
Correct |
3 ms |
1152 KB |
Output is correct |
37 |
Correct |
3 ms |
1152 KB |
Output is correct |
38 |
Correct |
3 ms |
1152 KB |
Output is correct |
39 |
Correct |
97 ms |
11640 KB |
Output is correct |
40 |
Correct |
69 ms |
11512 KB |
Output is correct |
41 |
Correct |
44 ms |
7928 KB |
Output is correct |
42 |
Correct |
11 ms |
2688 KB |
Output is correct |
43 |
Correct |
3 ms |
1152 KB |
Output is correct |
44 |
Correct |
3 ms |
1152 KB |
Output is correct |
45 |
Correct |
3 ms |
1152 KB |
Output is correct |
46 |
Correct |
3 ms |
1152 KB |
Output is correct |
47 |
Correct |
3 ms |
1152 KB |
Output is correct |
48 |
Correct |
2 ms |
1152 KB |
Output is correct |
49 |
Correct |
3 ms |
1152 KB |
Output is correct |
50 |
Correct |
3 ms |
1152 KB |
Output is correct |
51 |
Correct |
3 ms |
1152 KB |
Output is correct |
52 |
Correct |
3 ms |
1152 KB |
Output is correct |
53 |
Correct |
2 ms |
1152 KB |
Output is correct |
54 |
Correct |
4 ms |
1152 KB |
Output is correct |
55 |
Correct |
2 ms |
1152 KB |
Output is correct |
56 |
Correct |
3 ms |
1152 KB |
Output is correct |
57 |
Correct |
91 ms |
8760 KB |
Output is correct |
58 |
Correct |
87 ms |
8700 KB |
Output is correct |
59 |
Correct |
122 ms |
8696 KB |
Output is correct |
60 |
Correct |
80 ms |
8696 KB |
Output is correct |
61 |
Correct |
84 ms |
8568 KB |
Output is correct |
62 |
Correct |
69 ms |
8568 KB |
Output is correct |
63 |
Correct |
72 ms |
8440 KB |
Output is correct |
64 |
Runtime error |
76 ms |
16632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
65 |
Halted |
0 ms |
0 KB |
- |