#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);
for(auto i:nodes)
p[i]={-1,-1};
nodes.clear();
int B=A,sum=0,mini=INF,c=node,sh=INF;
maxi=0;
dfs(B,0);
nodes.clear();
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;
}
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);
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> >());
int centroid=center[0].first,ans=tree_d[0].fi,max_d=0;
for (int i = 0; i < idx-1; ++i)
{
if(center[tree_d[i+1].se].se>center[tree_d[i].se].se)
centroid=center[tree_d[i+1].se].fi;
ans=max(ans,center[tree_d[i+1].se].se+center[tree_d[i].se].se+L);
}
return ans;
}
Compilation message
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:53:6: warning: variable 'centroid' set but not used [-Wunused-but-set-variable]
int centroid=center[0].first,ans=tree_d[0].fi,max_d=0;
^~~~~~~~
dreaming.cpp:53:48: warning: unused variable 'max_d' [-Wunused-variable]
int centroid=center[0].first,ans=tree_d[0].fi,max_d=0;
^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
12020 KB |
Output is correct |
2 |
Correct |
58 ms |
11876 KB |
Output is correct |
3 |
Correct |
38 ms |
8008 KB |
Output is correct |
4 |
Correct |
9 ms |
2048 KB |
Output is correct |
5 |
Correct |
8 ms |
1408 KB |
Output is correct |
6 |
Correct |
14 ms |
2944 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
27 ms |
4728 KB |
Output is correct |
9 |
Correct |
33 ms |
6272 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
53 ms |
8188 KB |
Output is correct |
12 |
Correct |
62 ms |
9968 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
12020 KB |
Output is correct |
2 |
Correct |
58 ms |
11876 KB |
Output is correct |
3 |
Correct |
38 ms |
8008 KB |
Output is correct |
4 |
Correct |
9 ms |
2048 KB |
Output is correct |
5 |
Correct |
8 ms |
1408 KB |
Output is correct |
6 |
Correct |
14 ms |
2944 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
27 ms |
4728 KB |
Output is correct |
9 |
Correct |
33 ms |
6272 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
53 ms |
8188 KB |
Output is correct |
12 |
Correct |
62 ms |
9968 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
12020 KB |
Output is correct |
2 |
Correct |
58 ms |
11876 KB |
Output is correct |
3 |
Correct |
38 ms |
8008 KB |
Output is correct |
4 |
Correct |
9 ms |
2048 KB |
Output is correct |
5 |
Correct |
8 ms |
1408 KB |
Output is correct |
6 |
Correct |
14 ms |
2944 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
27 ms |
4728 KB |
Output is correct |
9 |
Correct |
33 ms |
6272 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
53 ms |
8188 KB |
Output is correct |
12 |
Correct |
62 ms |
9968 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
22 ms |
9728 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 |
59 ms |
12020 KB |
Output is correct |
2 |
Correct |
58 ms |
11876 KB |
Output is correct |
3 |
Correct |
38 ms |
8008 KB |
Output is correct |
4 |
Correct |
9 ms |
2048 KB |
Output is correct |
5 |
Correct |
8 ms |
1408 KB |
Output is correct |
6 |
Correct |
14 ms |
2944 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
27 ms |
4728 KB |
Output is correct |
9 |
Correct |
33 ms |
6272 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
53 ms |
8188 KB |
Output is correct |
12 |
Correct |
62 ms |
9968 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Runtime error |
3 ms |
768 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 |
59 ms |
12020 KB |
Output is correct |
2 |
Correct |
58 ms |
11876 KB |
Output is correct |
3 |
Correct |
38 ms |
8008 KB |
Output is correct |
4 |
Correct |
9 ms |
2048 KB |
Output is correct |
5 |
Correct |
8 ms |
1408 KB |
Output is correct |
6 |
Correct |
14 ms |
2944 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
27 ms |
4728 KB |
Output is correct |
9 |
Correct |
33 ms |
6272 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
53 ms |
8188 KB |
Output is correct |
12 |
Correct |
62 ms |
9968 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |