#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;
vector<vector<pair<int,int> >> adj;
vector<bool> vis;
vector<int> t,d;
int n,m,l;
void dfs(int node)
{
vis[node]=true;
int k=adj[node].size();
for(int x=0;x<k;x++)
{
int to=adj[node][x].first;
if(!vis[to])
dfs(to);
}
}
void dfs3(int node,int dis[])
{
vis[node]=true;
int k=adj[node].size();
for(int x=0;x<k;x++)
{
int to=adj[node][x].first;
if(!vis[to])
{
dis[to]=dis[node]+adj[node][x].second;
dfs3(to,dis);
}
}
}
int get(int y)
{
int dis[n+1]={0},disa[n+1]={0},disb[n+1]={0},a=0,b=0,cur=0;
vis.assign(n+1,false);
if(adj[y].size()!=0)
dfs3(y,dis);
else
return 0;
for(int x=1;x<=n;x++)
{
if(cur<=dis[x] && x!=y)
{
a=x;
cur=dis[x];
}
}
vis.assign(n+1,false);
dfs3(a,disa);
cur=0;
for(int x=1;x<=n;x++)
{
if(cur<disa[x] && x!=a)
{
b=x;
cur=disa[x];
}
}
vis.assign(n+1,false);
dfs3(b,disb);
int ans=disb[a];
for(int x=1;x<=n;x++)
{
if(disa[x]!=0 || disb[x]!=0)
ans=min(ans,max(disa[x],disb[x]));
}
d.push_back(disb[a]);
return ans;
}
int travelTime(int ne,int me,int le,int u[],int v[],int te[])
{
n=ne;m=me;l=le;
adj.resize(n+1);
vis.assign(n+1,false);
for(int x=0;x<m;x++)
{
adj[u[x]+1].push_back(make_pair(v[x]+1,te[x]));
adj[v[x]+1].push_back(make_pair(u[x]+1,te[x]));
}
int c=0;
for(int x=1;x<=n;x++)
{
if(!vis[x])
{
dfs(x);
t.push_back(x);
}
}
int z=t.size();
int dia[z]={0};
for(int x=0;x<z;x++)
dia[x]=get(t[x]);
int ans=0,ans1=0;
/*for(int x=0;x<z;x++)
cout<<t[x]<<" "<<dia[x]<<endl;*/
for(int x=0;x<d.size();x++)
ans=max(ans,d[x]);
sort(dia,dia+z);
int left=0,r=0,lo=1,ro=1;
for(int x=z-2;x>=0;x--)
{
if(left>r)
{
r=max(dia[x]+ro*l,r);
ro++;
}
else
{
left=max(dia[x]+lo*l,left);
lo++;
}
}
ans1=max(left+r,max(left,r)+dia[z-1]);
return max(ans1,ans);
}
/*int main()
{
int ne,me,le;
cin>>ne>>me>>le;
int te[me],ae[me],be[me];
for(int x=0;x<me;x++)
cin>>ae[x]>>be[x]>>te[x];
//for(int x=0;x<me;x++)
//ae[x]++,be[x]++;
cout<<travelTime(ne, me, le, ae , be , te );
}*/
Compilation message
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:97:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
97 | for(int x=0;x<d.size();x++)
| ~^~~~~~~~~
dreaming.cpp:81:9: warning: unused variable 'c' [-Wunused-variable]
81 | int c=0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
14284 KB |
Output is correct |
2 |
Correct |
40 ms |
14280 KB |
Output is correct |
3 |
Correct |
24 ms |
9592 KB |
Output is correct |
4 |
Correct |
5 ms |
2388 KB |
Output is correct |
5 |
Correct |
5 ms |
1524 KB |
Output is correct |
6 |
Correct |
10 ms |
3372 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
19 ms |
5460 KB |
Output is correct |
9 |
Correct |
26 ms |
7416 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
40 ms |
9900 KB |
Output is correct |
12 |
Correct |
41 ms |
11904 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
312 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
308 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
304 KB |
Output is correct |
20 |
Correct |
0 ms |
308 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
312 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
14284 KB |
Output is correct |
2 |
Correct |
40 ms |
14280 KB |
Output is correct |
3 |
Correct |
24 ms |
9592 KB |
Output is correct |
4 |
Correct |
5 ms |
2388 KB |
Output is correct |
5 |
Correct |
5 ms |
1524 KB |
Output is correct |
6 |
Correct |
10 ms |
3372 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
19 ms |
5460 KB |
Output is correct |
9 |
Correct |
26 ms |
7416 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
40 ms |
9900 KB |
Output is correct |
12 |
Correct |
41 ms |
11904 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
312 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
308 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
312 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
308 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
304 KB |
Output is correct |
33 |
Correct |
0 ms |
308 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
312 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
36 ms |
14352 KB |
Output is correct |
40 |
Correct |
46 ms |
14364 KB |
Output is correct |
41 |
Correct |
24 ms |
9656 KB |
Output is correct |
42 |
Correct |
6 ms |
2356 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
0 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
0 ms |
312 KB |
Output is correct |
47 |
Correct |
0 ms |
308 KB |
Output is correct |
48 |
Correct |
0 ms |
308 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
0 ms |
312 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
2 ms |
212 KB |
Output is correct |
56 |
Correct |
1 ms |
212 KB |
Output is correct |
57 |
Correct |
44 ms |
10340 KB |
Output is correct |
58 |
Correct |
47 ms |
10324 KB |
Output is correct |
59 |
Correct |
56 ms |
10292 KB |
Output is correct |
60 |
Correct |
50 ms |
10244 KB |
Output is correct |
61 |
Correct |
48 ms |
10252 KB |
Output is correct |
62 |
Correct |
46 ms |
10364 KB |
Output is correct |
63 |
Correct |
41 ms |
10044 KB |
Output is correct |
64 |
Correct |
41 ms |
10000 KB |
Output is correct |
65 |
Correct |
59 ms |
10296 KB |
Output is correct |
66 |
Correct |
44 ms |
10180 KB |
Output is correct |
67 |
Correct |
47 ms |
10280 KB |
Output is correct |
68 |
Correct |
46 ms |
10240 KB |
Output is correct |
69 |
Correct |
48 ms |
10516 KB |
Output is correct |
70 |
Correct |
48 ms |
10528 KB |
Output is correct |
71 |
Correct |
1 ms |
308 KB |
Output is correct |
72 |
Correct |
2 ms |
596 KB |
Output is correct |
73 |
Correct |
2 ms |
576 KB |
Output is correct |
74 |
Correct |
3 ms |
596 KB |
Output is correct |
75 |
Correct |
2 ms |
596 KB |
Output is correct |
76 |
Correct |
2 ms |
596 KB |
Output is correct |
77 |
Correct |
2 ms |
596 KB |
Output is correct |
78 |
Correct |
2 ms |
596 KB |
Output is correct |
79 |
Correct |
2 ms |
616 KB |
Output is correct |
80 |
Correct |
56 ms |
10156 KB |
Output is correct |
81 |
Correct |
45 ms |
10264 KB |
Output is correct |
82 |
Correct |
66 ms |
10360 KB |
Output is correct |
83 |
Correct |
47 ms |
10348 KB |
Output is correct |
84 |
Correct |
1 ms |
468 KB |
Output is correct |
85 |
Correct |
1 ms |
468 KB |
Output is correct |
86 |
Correct |
1 ms |
468 KB |
Output is correct |
87 |
Correct |
3 ms |
468 KB |
Output is correct |
88 |
Correct |
1 ms |
468 KB |
Output is correct |
89 |
Correct |
1 ms |
468 KB |
Output is correct |
90 |
Correct |
2 ms |
572 KB |
Output is correct |
91 |
Correct |
2 ms |
576 KB |
Output is correct |
92 |
Correct |
2 ms |
468 KB |
Output is correct |
93 |
Correct |
1 ms |
468 KB |
Output is correct |
94 |
Correct |
0 ms |
212 KB |
Output is correct |
95 |
Correct |
1 ms |
212 KB |
Output is correct |
96 |
Correct |
1 ms |
212 KB |
Output is correct |
97 |
Correct |
1 ms |
212 KB |
Output is correct |
98 |
Correct |
1 ms |
308 KB |
Output is correct |
99 |
Correct |
0 ms |
212 KB |
Output is correct |
100 |
Correct |
1 ms |
312 KB |
Output is correct |
101 |
Correct |
1 ms |
212 KB |
Output is correct |
102 |
Correct |
1 ms |
308 KB |
Output is correct |
103 |
Correct |
1 ms |
308 KB |
Output is correct |
104 |
Correct |
6 ms |
1472 KB |
Output is correct |
105 |
Correct |
14 ms |
3360 KB |
Output is correct |
106 |
Correct |
1 ms |
340 KB |
Output is correct |
107 |
Correct |
22 ms |
5468 KB |
Output is correct |
108 |
Correct |
24 ms |
7364 KB |
Output is correct |
109 |
Correct |
1 ms |
340 KB |
Output is correct |
110 |
Correct |
35 ms |
9804 KB |
Output is correct |
111 |
Correct |
42 ms |
11996 KB |
Output is correct |
112 |
Correct |
1 ms |
340 KB |
Output is correct |
113 |
Correct |
54 ms |
15948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1069 ms |
6876 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
312 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
308 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
304 KB |
Output is correct |
20 |
Correct |
0 ms |
308 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
312 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
320 KB |
Output is correct |
27 |
Incorrect |
4 ms |
468 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
14284 KB |
Output is correct |
2 |
Correct |
40 ms |
14280 KB |
Output is correct |
3 |
Correct |
24 ms |
9592 KB |
Output is correct |
4 |
Correct |
5 ms |
2388 KB |
Output is correct |
5 |
Correct |
5 ms |
1524 KB |
Output is correct |
6 |
Correct |
10 ms |
3372 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
19 ms |
5460 KB |
Output is correct |
9 |
Correct |
26 ms |
7416 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
40 ms |
9900 KB |
Output is correct |
12 |
Correct |
41 ms |
11904 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
312 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
308 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
312 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
308 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
304 KB |
Output is correct |
33 |
Correct |
0 ms |
308 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
312 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
36 ms |
14352 KB |
Output is correct |
40 |
Correct |
46 ms |
14364 KB |
Output is correct |
41 |
Correct |
24 ms |
9656 KB |
Output is correct |
42 |
Correct |
6 ms |
2356 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
0 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
0 ms |
312 KB |
Output is correct |
47 |
Correct |
0 ms |
308 KB |
Output is correct |
48 |
Correct |
0 ms |
308 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
0 ms |
312 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
2 ms |
212 KB |
Output is correct |
56 |
Correct |
1 ms |
212 KB |
Output is correct |
57 |
Correct |
44 ms |
10340 KB |
Output is correct |
58 |
Correct |
47 ms |
10324 KB |
Output is correct |
59 |
Correct |
56 ms |
10292 KB |
Output is correct |
60 |
Correct |
50 ms |
10244 KB |
Output is correct |
61 |
Correct |
48 ms |
10252 KB |
Output is correct |
62 |
Correct |
46 ms |
10364 KB |
Output is correct |
63 |
Correct |
41 ms |
10044 KB |
Output is correct |
64 |
Correct |
41 ms |
10000 KB |
Output is correct |
65 |
Correct |
59 ms |
10296 KB |
Output is correct |
66 |
Correct |
44 ms |
10180 KB |
Output is correct |
67 |
Correct |
47 ms |
10280 KB |
Output is correct |
68 |
Correct |
46 ms |
10240 KB |
Output is correct |
69 |
Correct |
48 ms |
10516 KB |
Output is correct |
70 |
Correct |
48 ms |
10528 KB |
Output is correct |
71 |
Correct |
1 ms |
308 KB |
Output is correct |
72 |
Correct |
2 ms |
596 KB |
Output is correct |
73 |
Correct |
2 ms |
576 KB |
Output is correct |
74 |
Correct |
3 ms |
596 KB |
Output is correct |
75 |
Correct |
2 ms |
596 KB |
Output is correct |
76 |
Correct |
2 ms |
596 KB |
Output is correct |
77 |
Correct |
2 ms |
596 KB |
Output is correct |
78 |
Correct |
2 ms |
596 KB |
Output is correct |
79 |
Correct |
2 ms |
616 KB |
Output is correct |
80 |
Correct |
56 ms |
10156 KB |
Output is correct |
81 |
Correct |
45 ms |
10264 KB |
Output is correct |
82 |
Correct |
66 ms |
10360 KB |
Output is correct |
83 |
Correct |
47 ms |
10348 KB |
Output is correct |
84 |
Correct |
1 ms |
468 KB |
Output is correct |
85 |
Correct |
1 ms |
468 KB |
Output is correct |
86 |
Correct |
1 ms |
468 KB |
Output is correct |
87 |
Correct |
3 ms |
468 KB |
Output is correct |
88 |
Correct |
1 ms |
468 KB |
Output is correct |
89 |
Correct |
1 ms |
468 KB |
Output is correct |
90 |
Correct |
2 ms |
572 KB |
Output is correct |
91 |
Correct |
2 ms |
576 KB |
Output is correct |
92 |
Correct |
2 ms |
468 KB |
Output is correct |
93 |
Correct |
1 ms |
468 KB |
Output is correct |
94 |
Correct |
0 ms |
212 KB |
Output is correct |
95 |
Correct |
1 ms |
212 KB |
Output is correct |
96 |
Correct |
1 ms |
212 KB |
Output is correct |
97 |
Correct |
1 ms |
212 KB |
Output is correct |
98 |
Correct |
1 ms |
308 KB |
Output is correct |
99 |
Correct |
0 ms |
212 KB |
Output is correct |
100 |
Correct |
1 ms |
312 KB |
Output is correct |
101 |
Correct |
1 ms |
212 KB |
Output is correct |
102 |
Correct |
1 ms |
308 KB |
Output is correct |
103 |
Correct |
1 ms |
308 KB |
Output is correct |
104 |
Correct |
6 ms |
1472 KB |
Output is correct |
105 |
Correct |
14 ms |
3360 KB |
Output is correct |
106 |
Correct |
1 ms |
340 KB |
Output is correct |
107 |
Correct |
22 ms |
5468 KB |
Output is correct |
108 |
Correct |
24 ms |
7364 KB |
Output is correct |
109 |
Correct |
1 ms |
340 KB |
Output is correct |
110 |
Correct |
35 ms |
9804 KB |
Output is correct |
111 |
Correct |
42 ms |
11996 KB |
Output is correct |
112 |
Correct |
1 ms |
340 KB |
Output is correct |
113 |
Correct |
54 ms |
15948 KB |
Output is correct |
114 |
Execution timed out |
1069 ms |
6876 KB |
Time limit exceeded |
115 |
Halted |
0 ms |
0 KB |
- |