#include <bits/stdc++.h>
using namespace std;
#include "dreaming.h"
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define NN 100005
vector < pair<int,int> > V[NN];
int H[NN],M[NN],node[NN],M2[NN],mn,ss;
void f(int x){
H[x] = 1;
int t;
for(int i=0; i<V[x].size(); i++){
if(H[ V[x][i].st ]) continue;
f(V[x][i].st);
t = M[ V[x][i].st ] + V[x][i].nd;
if(M[x] < t) { M2[x] = M[x]; M[x] = t; node[x] = V[x][i].st; }
else if(M2[x] < t) M2[x] = t;
}
ss = max(ss , M[x] + M2[x]);
}
void g(int x, int p, int t){
mn = min(mn , max(M[x] , t));
for(int i=0; i<V[x].size(); i++){
if(V[x][i].st == p) continue;
int a = max(t , node[x] == V[x][i].st ? M2[x] : M[x]);
g(V[x][i].st , x , a + V[x][i].nd);
}
}
int travelTime(int n, int m, int l, int *A, int *B, int *T){
int t,i,x=-1;
for(i=0;i<m;i++){
V[ A[i] ].pb(mp(B[i],T[i]));
V[ B[i] ].pb(mp(A[i],T[i]));
}
for(i=0;i<n;i++){
if(H[i]) continue;
mn = 1e9;
f(i);
g(i,-1,0);
//cout << i << " " << x << " " << mn << " ss\n";
if(x == -1){
x = mn;
continue;
}
ss = max(ss , x + mn + l);
x = min(max(mn , x+l) , max(x , mn+l));
}
return ss;
}
Compilation message
dreaming.cpp: In function 'void f(int)':
dreaming.cpp:17:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<V[x].size(); i++){
~^~~~~~~~~~~~
dreaming.cpp: In function 'void g(int, int, int)':
dreaming.cpp:28:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<V[x].size(); i++){
~^~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:36:9: warning: unused variable 't' [-Wunused-variable]
int t,i,x=-1;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
12024 KB |
Output is correct |
2 |
Correct |
82 ms |
11772 KB |
Output is correct |
3 |
Correct |
43 ms |
10232 KB |
Output is correct |
4 |
Correct |
11 ms |
4096 KB |
Output is correct |
5 |
Correct |
9 ms |
3456 KB |
Output is correct |
6 |
Correct |
18 ms |
4736 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
27 ms |
6528 KB |
Output is correct |
9 |
Correct |
39 ms |
8704 KB |
Output is correct |
10 |
Correct |
4 ms |
2788 KB |
Output is correct |
11 |
Correct |
52 ms |
9464 KB |
Output is correct |
12 |
Correct |
64 ms |
10744 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
12024 KB |
Output is correct |
2 |
Correct |
82 ms |
11772 KB |
Output is correct |
3 |
Correct |
43 ms |
10232 KB |
Output is correct |
4 |
Correct |
11 ms |
4096 KB |
Output is correct |
5 |
Correct |
9 ms |
3456 KB |
Output is correct |
6 |
Correct |
18 ms |
4736 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
27 ms |
6528 KB |
Output is correct |
9 |
Correct |
39 ms |
8704 KB |
Output is correct |
10 |
Correct |
4 ms |
2788 KB |
Output is correct |
11 |
Correct |
52 ms |
9464 KB |
Output is correct |
12 |
Correct |
64 ms |
10744 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
14 |
Correct |
4 ms |
2688 KB |
Output is correct |
15 |
Correct |
5 ms |
2688 KB |
Output is correct |
16 |
Correct |
3 ms |
2688 KB |
Output is correct |
17 |
Correct |
4 ms |
2688 KB |
Output is correct |
18 |
Correct |
4 ms |
2688 KB |
Output is correct |
19 |
Correct |
4 ms |
2688 KB |
Output is correct |
20 |
Correct |
4 ms |
2688 KB |
Output is correct |
21 |
Correct |
4 ms |
2688 KB |
Output is correct |
22 |
Correct |
4 ms |
2688 KB |
Output is correct |
23 |
Correct |
4 ms |
2688 KB |
Output is correct |
24 |
Correct |
4 ms |
2688 KB |
Output is correct |
25 |
Correct |
3 ms |
2688 KB |
Output is correct |
26 |
Correct |
4 ms |
2688 KB |
Output is correct |
27 |
Correct |
4 ms |
2688 KB |
Output is correct |
28 |
Correct |
4 ms |
2688 KB |
Output is correct |
29 |
Correct |
4 ms |
2688 KB |
Output is correct |
30 |
Correct |
4 ms |
2688 KB |
Output is correct |
31 |
Correct |
4 ms |
2688 KB |
Output is correct |
32 |
Correct |
4 ms |
2688 KB |
Output is correct |
33 |
Correct |
4 ms |
2688 KB |
Output is correct |
34 |
Correct |
3 ms |
2688 KB |
Output is correct |
35 |
Correct |
3 ms |
2688 KB |
Output is correct |
36 |
Correct |
3 ms |
2688 KB |
Output is correct |
37 |
Correct |
4 ms |
2688 KB |
Output is correct |
38 |
Correct |
3 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
12024 KB |
Output is correct |
2 |
Correct |
82 ms |
11772 KB |
Output is correct |
3 |
Correct |
43 ms |
10232 KB |
Output is correct |
4 |
Correct |
11 ms |
4096 KB |
Output is correct |
5 |
Correct |
9 ms |
3456 KB |
Output is correct |
6 |
Correct |
18 ms |
4736 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
27 ms |
6528 KB |
Output is correct |
9 |
Correct |
39 ms |
8704 KB |
Output is correct |
10 |
Correct |
4 ms |
2788 KB |
Output is correct |
11 |
Correct |
52 ms |
9464 KB |
Output is correct |
12 |
Correct |
64 ms |
10744 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
14 |
Correct |
4 ms |
2688 KB |
Output is correct |
15 |
Correct |
5 ms |
2688 KB |
Output is correct |
16 |
Correct |
3 ms |
2688 KB |
Output is correct |
17 |
Correct |
4 ms |
2688 KB |
Output is correct |
18 |
Correct |
4 ms |
2688 KB |
Output is correct |
19 |
Correct |
4 ms |
2688 KB |
Output is correct |
20 |
Correct |
4 ms |
2688 KB |
Output is correct |
21 |
Correct |
4 ms |
2688 KB |
Output is correct |
22 |
Correct |
4 ms |
2688 KB |
Output is correct |
23 |
Correct |
4 ms |
2688 KB |
Output is correct |
24 |
Correct |
4 ms |
2688 KB |
Output is correct |
25 |
Correct |
3 ms |
2688 KB |
Output is correct |
26 |
Correct |
4 ms |
2688 KB |
Output is correct |
27 |
Correct |
4 ms |
2688 KB |
Output is correct |
28 |
Correct |
4 ms |
2688 KB |
Output is correct |
29 |
Correct |
4 ms |
2688 KB |
Output is correct |
30 |
Correct |
4 ms |
2688 KB |
Output is correct |
31 |
Correct |
4 ms |
2688 KB |
Output is correct |
32 |
Correct |
4 ms |
2688 KB |
Output is correct |
33 |
Correct |
4 ms |
2688 KB |
Output is correct |
34 |
Correct |
3 ms |
2688 KB |
Output is correct |
35 |
Correct |
3 ms |
2688 KB |
Output is correct |
36 |
Correct |
3 ms |
2688 KB |
Output is correct |
37 |
Correct |
4 ms |
2688 KB |
Output is correct |
38 |
Correct |
3 ms |
2816 KB |
Output is correct |
39 |
Correct |
71 ms |
11940 KB |
Output is correct |
40 |
Correct |
74 ms |
11672 KB |
Output is correct |
41 |
Correct |
41 ms |
10160 KB |
Output is correct |
42 |
Correct |
11 ms |
4096 KB |
Output is correct |
43 |
Correct |
3 ms |
2688 KB |
Output is correct |
44 |
Correct |
4 ms |
2688 KB |
Output is correct |
45 |
Correct |
4 ms |
2688 KB |
Output is correct |
46 |
Correct |
4 ms |
2688 KB |
Output is correct |
47 |
Correct |
3 ms |
2816 KB |
Output is correct |
48 |
Correct |
4 ms |
2688 KB |
Output is correct |
49 |
Correct |
3 ms |
2688 KB |
Output is correct |
50 |
Correct |
3 ms |
2688 KB |
Output is correct |
51 |
Correct |
4 ms |
2688 KB |
Output is correct |
52 |
Correct |
4 ms |
2688 KB |
Output is correct |
53 |
Correct |
3 ms |
2688 KB |
Output is correct |
54 |
Correct |
4 ms |
2688 KB |
Output is correct |
55 |
Correct |
3 ms |
2688 KB |
Output is correct |
56 |
Correct |
4 ms |
2688 KB |
Output is correct |
57 |
Correct |
72 ms |
9592 KB |
Output is correct |
58 |
Correct |
70 ms |
9464 KB |
Output is correct |
59 |
Correct |
99 ms |
9388 KB |
Output is correct |
60 |
Correct |
89 ms |
9336 KB |
Output is correct |
61 |
Correct |
71 ms |
9208 KB |
Output is correct |
62 |
Correct |
86 ms |
9208 KB |
Output is correct |
63 |
Correct |
66 ms |
9080 KB |
Output is correct |
64 |
Correct |
64 ms |
9080 KB |
Output is correct |
65 |
Correct |
65 ms |
9036 KB |
Output is correct |
66 |
Correct |
69 ms |
9080 KB |
Output is correct |
67 |
Correct |
69 ms |
9336 KB |
Output is correct |
68 |
Correct |
79 ms |
9336 KB |
Output is correct |
69 |
Correct |
82 ms |
9336 KB |
Output is correct |
70 |
Correct |
70 ms |
9336 KB |
Output is correct |
71 |
Correct |
4 ms |
2688 KB |
Output is correct |
72 |
Correct |
5 ms |
2944 KB |
Output is correct |
73 |
Correct |
5 ms |
2944 KB |
Output is correct |
74 |
Correct |
5 ms |
2944 KB |
Output is correct |
75 |
Correct |
5 ms |
2944 KB |
Output is correct |
76 |
Correct |
5 ms |
2944 KB |
Output is correct |
77 |
Correct |
6 ms |
2944 KB |
Output is correct |
78 |
Correct |
5 ms |
2944 KB |
Output is correct |
79 |
Correct |
5 ms |
2944 KB |
Output is correct |
80 |
Correct |
71 ms |
9408 KB |
Output is correct |
81 |
Correct |
71 ms |
9280 KB |
Output is correct |
82 |
Correct |
78 ms |
9208 KB |
Output is correct |
83 |
Correct |
69 ms |
9208 KB |
Output is correct |
84 |
Correct |
4 ms |
2944 KB |
Output is correct |
85 |
Correct |
5 ms |
2816 KB |
Output is correct |
86 |
Correct |
5 ms |
2944 KB |
Output is correct |
87 |
Correct |
5 ms |
2944 KB |
Output is correct |
88 |
Correct |
5 ms |
2816 KB |
Output is correct |
89 |
Correct |
5 ms |
2816 KB |
Output is correct |
90 |
Correct |
5 ms |
2944 KB |
Output is correct |
91 |
Correct |
5 ms |
2944 KB |
Output is correct |
92 |
Correct |
5 ms |
2944 KB |
Output is correct |
93 |
Correct |
5 ms |
2944 KB |
Output is correct |
94 |
Correct |
3 ms |
2688 KB |
Output is correct |
95 |
Correct |
4 ms |
2688 KB |
Output is correct |
96 |
Correct |
4 ms |
2688 KB |
Output is correct |
97 |
Correct |
4 ms |
2688 KB |
Output is correct |
98 |
Correct |
3 ms |
2688 KB |
Output is correct |
99 |
Correct |
3 ms |
2688 KB |
Output is correct |
100 |
Correct |
3 ms |
2688 KB |
Output is correct |
101 |
Correct |
4 ms |
2688 KB |
Output is correct |
102 |
Correct |
6 ms |
2688 KB |
Output is correct |
103 |
Correct |
4 ms |
2688 KB |
Output is correct |
104 |
Correct |
9 ms |
3584 KB |
Output is correct |
105 |
Correct |
16 ms |
4736 KB |
Output is correct |
106 |
Correct |
4 ms |
2688 KB |
Output is correct |
107 |
Correct |
30 ms |
6648 KB |
Output is correct |
108 |
Correct |
40 ms |
8824 KB |
Output is correct |
109 |
Correct |
4 ms |
2816 KB |
Output is correct |
110 |
Correct |
52 ms |
9508 KB |
Output is correct |
111 |
Correct |
57 ms |
10616 KB |
Output is correct |
112 |
Correct |
7 ms |
2816 KB |
Output is correct |
113 |
Correct |
104 ms |
16248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
6528 KB |
Output is correct |
2 |
Incorrect |
23 ms |
6520 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
12024 KB |
Output is correct |
2 |
Correct |
82 ms |
11772 KB |
Output is correct |
3 |
Correct |
43 ms |
10232 KB |
Output is correct |
4 |
Correct |
11 ms |
4096 KB |
Output is correct |
5 |
Correct |
9 ms |
3456 KB |
Output is correct |
6 |
Correct |
18 ms |
4736 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
27 ms |
6528 KB |
Output is correct |
9 |
Correct |
39 ms |
8704 KB |
Output is correct |
10 |
Correct |
4 ms |
2788 KB |
Output is correct |
11 |
Correct |
52 ms |
9464 KB |
Output is correct |
12 |
Correct |
64 ms |
10744 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
14 |
Correct |
5 ms |
2816 KB |
Output is correct |
15 |
Correct |
4 ms |
2816 KB |
Output is correct |
16 |
Correct |
5 ms |
2944 KB |
Output is correct |
17 |
Correct |
4 ms |
2816 KB |
Output is correct |
18 |
Correct |
4 ms |
2816 KB |
Output is correct |
19 |
Correct |
5 ms |
2944 KB |
Output is correct |
20 |
Correct |
4 ms |
2816 KB |
Output is correct |
21 |
Incorrect |
5 ms |
2816 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
12024 KB |
Output is correct |
2 |
Correct |
82 ms |
11772 KB |
Output is correct |
3 |
Correct |
43 ms |
10232 KB |
Output is correct |
4 |
Correct |
11 ms |
4096 KB |
Output is correct |
5 |
Correct |
9 ms |
3456 KB |
Output is correct |
6 |
Correct |
18 ms |
4736 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
27 ms |
6528 KB |
Output is correct |
9 |
Correct |
39 ms |
8704 KB |
Output is correct |
10 |
Correct |
4 ms |
2788 KB |
Output is correct |
11 |
Correct |
52 ms |
9464 KB |
Output is correct |
12 |
Correct |
64 ms |
10744 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
14 |
Correct |
4 ms |
2688 KB |
Output is correct |
15 |
Correct |
5 ms |
2688 KB |
Output is correct |
16 |
Correct |
3 ms |
2688 KB |
Output is correct |
17 |
Correct |
4 ms |
2688 KB |
Output is correct |
18 |
Correct |
4 ms |
2688 KB |
Output is correct |
19 |
Correct |
4 ms |
2688 KB |
Output is correct |
20 |
Correct |
4 ms |
2688 KB |
Output is correct |
21 |
Correct |
4 ms |
2688 KB |
Output is correct |
22 |
Correct |
4 ms |
2688 KB |
Output is correct |
23 |
Correct |
4 ms |
2688 KB |
Output is correct |
24 |
Correct |
4 ms |
2688 KB |
Output is correct |
25 |
Correct |
3 ms |
2688 KB |
Output is correct |
26 |
Correct |
4 ms |
2688 KB |
Output is correct |
27 |
Correct |
4 ms |
2688 KB |
Output is correct |
28 |
Correct |
4 ms |
2688 KB |
Output is correct |
29 |
Correct |
4 ms |
2688 KB |
Output is correct |
30 |
Correct |
4 ms |
2688 KB |
Output is correct |
31 |
Correct |
4 ms |
2688 KB |
Output is correct |
32 |
Correct |
4 ms |
2688 KB |
Output is correct |
33 |
Correct |
4 ms |
2688 KB |
Output is correct |
34 |
Correct |
3 ms |
2688 KB |
Output is correct |
35 |
Correct |
3 ms |
2688 KB |
Output is correct |
36 |
Correct |
3 ms |
2688 KB |
Output is correct |
37 |
Correct |
4 ms |
2688 KB |
Output is correct |
38 |
Correct |
3 ms |
2816 KB |
Output is correct |
39 |
Correct |
71 ms |
11940 KB |
Output is correct |
40 |
Correct |
74 ms |
11672 KB |
Output is correct |
41 |
Correct |
41 ms |
10160 KB |
Output is correct |
42 |
Correct |
11 ms |
4096 KB |
Output is correct |
43 |
Correct |
3 ms |
2688 KB |
Output is correct |
44 |
Correct |
4 ms |
2688 KB |
Output is correct |
45 |
Correct |
4 ms |
2688 KB |
Output is correct |
46 |
Correct |
4 ms |
2688 KB |
Output is correct |
47 |
Correct |
3 ms |
2816 KB |
Output is correct |
48 |
Correct |
4 ms |
2688 KB |
Output is correct |
49 |
Correct |
3 ms |
2688 KB |
Output is correct |
50 |
Correct |
3 ms |
2688 KB |
Output is correct |
51 |
Correct |
4 ms |
2688 KB |
Output is correct |
52 |
Correct |
4 ms |
2688 KB |
Output is correct |
53 |
Correct |
3 ms |
2688 KB |
Output is correct |
54 |
Correct |
4 ms |
2688 KB |
Output is correct |
55 |
Correct |
3 ms |
2688 KB |
Output is correct |
56 |
Correct |
4 ms |
2688 KB |
Output is correct |
57 |
Correct |
72 ms |
9592 KB |
Output is correct |
58 |
Correct |
70 ms |
9464 KB |
Output is correct |
59 |
Correct |
99 ms |
9388 KB |
Output is correct |
60 |
Correct |
89 ms |
9336 KB |
Output is correct |
61 |
Correct |
71 ms |
9208 KB |
Output is correct |
62 |
Correct |
86 ms |
9208 KB |
Output is correct |
63 |
Correct |
66 ms |
9080 KB |
Output is correct |
64 |
Correct |
64 ms |
9080 KB |
Output is correct |
65 |
Correct |
65 ms |
9036 KB |
Output is correct |
66 |
Correct |
69 ms |
9080 KB |
Output is correct |
67 |
Correct |
69 ms |
9336 KB |
Output is correct |
68 |
Correct |
79 ms |
9336 KB |
Output is correct |
69 |
Correct |
82 ms |
9336 KB |
Output is correct |
70 |
Correct |
70 ms |
9336 KB |
Output is correct |
71 |
Correct |
4 ms |
2688 KB |
Output is correct |
72 |
Correct |
5 ms |
2944 KB |
Output is correct |
73 |
Correct |
5 ms |
2944 KB |
Output is correct |
74 |
Correct |
5 ms |
2944 KB |
Output is correct |
75 |
Correct |
5 ms |
2944 KB |
Output is correct |
76 |
Correct |
5 ms |
2944 KB |
Output is correct |
77 |
Correct |
6 ms |
2944 KB |
Output is correct |
78 |
Correct |
5 ms |
2944 KB |
Output is correct |
79 |
Correct |
5 ms |
2944 KB |
Output is correct |
80 |
Correct |
71 ms |
9408 KB |
Output is correct |
81 |
Correct |
71 ms |
9280 KB |
Output is correct |
82 |
Correct |
78 ms |
9208 KB |
Output is correct |
83 |
Correct |
69 ms |
9208 KB |
Output is correct |
84 |
Correct |
4 ms |
2944 KB |
Output is correct |
85 |
Correct |
5 ms |
2816 KB |
Output is correct |
86 |
Correct |
5 ms |
2944 KB |
Output is correct |
87 |
Correct |
5 ms |
2944 KB |
Output is correct |
88 |
Correct |
5 ms |
2816 KB |
Output is correct |
89 |
Correct |
5 ms |
2816 KB |
Output is correct |
90 |
Correct |
5 ms |
2944 KB |
Output is correct |
91 |
Correct |
5 ms |
2944 KB |
Output is correct |
92 |
Correct |
5 ms |
2944 KB |
Output is correct |
93 |
Correct |
5 ms |
2944 KB |
Output is correct |
94 |
Correct |
3 ms |
2688 KB |
Output is correct |
95 |
Correct |
4 ms |
2688 KB |
Output is correct |
96 |
Correct |
4 ms |
2688 KB |
Output is correct |
97 |
Correct |
4 ms |
2688 KB |
Output is correct |
98 |
Correct |
3 ms |
2688 KB |
Output is correct |
99 |
Correct |
3 ms |
2688 KB |
Output is correct |
100 |
Correct |
3 ms |
2688 KB |
Output is correct |
101 |
Correct |
4 ms |
2688 KB |
Output is correct |
102 |
Correct |
6 ms |
2688 KB |
Output is correct |
103 |
Correct |
4 ms |
2688 KB |
Output is correct |
104 |
Correct |
9 ms |
3584 KB |
Output is correct |
105 |
Correct |
16 ms |
4736 KB |
Output is correct |
106 |
Correct |
4 ms |
2688 KB |
Output is correct |
107 |
Correct |
30 ms |
6648 KB |
Output is correct |
108 |
Correct |
40 ms |
8824 KB |
Output is correct |
109 |
Correct |
4 ms |
2816 KB |
Output is correct |
110 |
Correct |
52 ms |
9508 KB |
Output is correct |
111 |
Correct |
57 ms |
10616 KB |
Output is correct |
112 |
Correct |
7 ms |
2816 KB |
Output is correct |
113 |
Correct |
104 ms |
16248 KB |
Output is correct |
114 |
Correct |
27 ms |
6528 KB |
Output is correct |
115 |
Incorrect |
23 ms |
6520 KB |
Output isn't correct |
116 |
Halted |
0 ms |
0 KB |
- |