#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+5;
struct edge
{
long long ver,dist;
edge(){};
edge(int vi, long long di)
{
ver = vi;
dist = di;
}
};
int n;
vector<edge> g[MAXN];
long long sub[MAXN],used[MAXN];
long long mind,vut;
vector<long long> comp;
void clear_used()
{
for(int i = 0; i < n; i++) used[i] = 0;
}
void dfs_dp(int beg, long long gor)
{
used[beg] = 1;
long long maxch = max(sub[beg],gor);
vut = max(vut,maxch);
mind = min(mind,maxch);
long long fir = 0, sec = 0;
for(edge nb : g[beg])
{
if(!used[nb.ver])
{
if(nb.dist+sub[nb.ver] >= fir)
{
sec = fir;
fir = nb.dist+sub[nb.ver];
}
else if(nb.dist+sub[nb.ver] >= sec)
{
sec = nb.dist+sub[nb.ver];
}
}
}
for(edge nb : g[beg])
{
if(!used[nb.ver])
{
long long new_gor = gor;
if(nb.dist+sub[nb.ver] == fir) new_gor = max(new_gor,sec);
else new_gor = max(new_gor,fir);
new_gor += nb.dist;
dfs_dp(nb.ver,new_gor);
}
}
}
void dfs(int beg)
{
used[beg] = 1;
for(edge nb : g[beg])
{
if(!used[nb.ver])
{
dfs(nb.ver);
sub[beg] = max(sub[beg],sub[nb.ver]+nb.dist);
}
}
}
int travelTime(int N,int M,int L,int A[],int B[],int T[])
{
n = N;
for(int i = 0; i < M; i++)
{
g[A[i]].push_back({B[i],T[i]});
g[B[i]].push_back({A[i],T[i]});
}
for(int i = 0; i < N; i++) if(!used[i]) dfs(i);
clear_used();
for(int i = 0; i < N; i++)
{
if(!used[i])
{
mind = 1e9+5;
dfs_dp(i,0);
comp.push_back(mind);
}
}
return max(comp[0]+comp[1]+L,vut);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
13924 KB |
Output is correct |
2 |
Correct |
43 ms |
13628 KB |
Output is correct |
3 |
Correct |
39 ms |
12412 KB |
Output is correct |
4 |
Correct |
6 ms |
6488 KB |
Output is correct |
5 |
Correct |
6 ms |
5976 KB |
Output is correct |
6 |
Correct |
10 ms |
7212 KB |
Output is correct |
7 |
Correct |
1 ms |
5212 KB |
Output is correct |
8 |
Correct |
17 ms |
9052 KB |
Output is correct |
9 |
Correct |
47 ms |
11012 KB |
Output is correct |
10 |
Correct |
2 ms |
5212 KB |
Output is correct |
11 |
Correct |
29 ms |
11600 KB |
Output is correct |
12 |
Correct |
63 ms |
12680 KB |
Output is correct |
13 |
Correct |
2 ms |
5208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5212 KB |
Output is correct |
2 |
Correct |
2 ms |
5212 KB |
Output is correct |
3 |
Correct |
2 ms |
5212 KB |
Output is correct |
4 |
Correct |
2 ms |
5212 KB |
Output is correct |
5 |
Correct |
2 ms |
5212 KB |
Output is correct |
6 |
Correct |
1 ms |
5212 KB |
Output is correct |
7 |
Correct |
1 ms |
5212 KB |
Output is correct |
8 |
Correct |
1 ms |
5212 KB |
Output is correct |
9 |
Correct |
2 ms |
5212 KB |
Output is correct |
10 |
Correct |
2 ms |
5212 KB |
Output is correct |
11 |
Correct |
1 ms |
5212 KB |
Output is correct |
12 |
Correct |
1 ms |
5212 KB |
Output is correct |
13 |
Correct |
1 ms |
5212 KB |
Output is correct |
14 |
Correct |
1 ms |
5212 KB |
Output is correct |
15 |
Correct |
1 ms |
5208 KB |
Output is correct |
16 |
Correct |
2 ms |
5212 KB |
Output is correct |
17 |
Correct |
1 ms |
5212 KB |
Output is correct |
18 |
Correct |
2 ms |
5212 KB |
Output is correct |
19 |
Correct |
1 ms |
5212 KB |
Output is correct |
20 |
Correct |
1 ms |
5208 KB |
Output is correct |
21 |
Correct |
1 ms |
5212 KB |
Output is correct |
22 |
Correct |
2 ms |
5212 KB |
Output is correct |
23 |
Correct |
2 ms |
5212 KB |
Output is correct |
24 |
Correct |
1 ms |
5212 KB |
Output is correct |
25 |
Correct |
1 ms |
5284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
13924 KB |
Output is correct |
2 |
Correct |
43 ms |
13628 KB |
Output is correct |
3 |
Correct |
39 ms |
12412 KB |
Output is correct |
4 |
Correct |
6 ms |
6488 KB |
Output is correct |
5 |
Correct |
6 ms |
5976 KB |
Output is correct |
6 |
Correct |
10 ms |
7212 KB |
Output is correct |
7 |
Correct |
1 ms |
5212 KB |
Output is correct |
8 |
Correct |
17 ms |
9052 KB |
Output is correct |
9 |
Correct |
47 ms |
11012 KB |
Output is correct |
10 |
Correct |
2 ms |
5212 KB |
Output is correct |
11 |
Correct |
29 ms |
11600 KB |
Output is correct |
12 |
Correct |
63 ms |
12680 KB |
Output is correct |
13 |
Correct |
2 ms |
5208 KB |
Output is correct |
14 |
Correct |
2 ms |
5212 KB |
Output is correct |
15 |
Correct |
2 ms |
5212 KB |
Output is correct |
16 |
Correct |
2 ms |
5212 KB |
Output is correct |
17 |
Correct |
2 ms |
5212 KB |
Output is correct |
18 |
Correct |
2 ms |
5212 KB |
Output is correct |
19 |
Correct |
1 ms |
5212 KB |
Output is correct |
20 |
Correct |
1 ms |
5212 KB |
Output is correct |
21 |
Correct |
1 ms |
5212 KB |
Output is correct |
22 |
Correct |
2 ms |
5212 KB |
Output is correct |
23 |
Correct |
2 ms |
5212 KB |
Output is correct |
24 |
Correct |
1 ms |
5212 KB |
Output is correct |
25 |
Correct |
1 ms |
5212 KB |
Output is correct |
26 |
Correct |
1 ms |
5212 KB |
Output is correct |
27 |
Correct |
1 ms |
5212 KB |
Output is correct |
28 |
Correct |
1 ms |
5208 KB |
Output is correct |
29 |
Correct |
2 ms |
5212 KB |
Output is correct |
30 |
Correct |
1 ms |
5212 KB |
Output is correct |
31 |
Correct |
2 ms |
5212 KB |
Output is correct |
32 |
Correct |
1 ms |
5212 KB |
Output is correct |
33 |
Correct |
1 ms |
5208 KB |
Output is correct |
34 |
Correct |
1 ms |
5212 KB |
Output is correct |
35 |
Correct |
2 ms |
5212 KB |
Output is correct |
36 |
Correct |
2 ms |
5212 KB |
Output is correct |
37 |
Correct |
1 ms |
5212 KB |
Output is correct |
38 |
Correct |
1 ms |
5284 KB |
Output is correct |
39 |
Correct |
61 ms |
13836 KB |
Output is correct |
40 |
Correct |
37 ms |
13596 KB |
Output is correct |
41 |
Correct |
25 ms |
12628 KB |
Output is correct |
42 |
Correct |
6 ms |
6488 KB |
Output is correct |
43 |
Correct |
1 ms |
5212 KB |
Output is correct |
44 |
Correct |
1 ms |
5208 KB |
Output is correct |
45 |
Correct |
1 ms |
5212 KB |
Output is correct |
46 |
Correct |
1 ms |
5212 KB |
Output is correct |
47 |
Correct |
2 ms |
5212 KB |
Output is correct |
48 |
Correct |
1 ms |
5208 KB |
Output is correct |
49 |
Correct |
2 ms |
5208 KB |
Output is correct |
50 |
Correct |
1 ms |
5208 KB |
Output is correct |
51 |
Correct |
1 ms |
5212 KB |
Output is correct |
52 |
Correct |
2 ms |
5212 KB |
Output is correct |
53 |
Correct |
1 ms |
5212 KB |
Output is correct |
54 |
Correct |
2 ms |
5212 KB |
Output is correct |
55 |
Correct |
2 ms |
5212 KB |
Output is correct |
56 |
Correct |
2 ms |
5208 KB |
Output is correct |
57 |
Correct |
47 ms |
11816 KB |
Output is correct |
58 |
Correct |
42 ms |
11704 KB |
Output is correct |
59 |
Correct |
52 ms |
11260 KB |
Output is correct |
60 |
Correct |
71 ms |
11364 KB |
Output is correct |
61 |
Correct |
72 ms |
11144 KB |
Output is correct |
62 |
Correct |
51 ms |
11196 KB |
Output is correct |
63 |
Correct |
68 ms |
11012 KB |
Output is correct |
64 |
Correct |
74 ms |
10924 KB |
Output is correct |
65 |
Correct |
68 ms |
11176 KB |
Output is correct |
66 |
Correct |
48 ms |
11224 KB |
Output is correct |
67 |
Correct |
44 ms |
11552 KB |
Output is correct |
68 |
Correct |
49 ms |
11336 KB |
Output is correct |
69 |
Correct |
51 ms |
11600 KB |
Output is correct |
70 |
Correct |
72 ms |
11392 KB |
Output is correct |
71 |
Correct |
1 ms |
5212 KB |
Output is correct |
72 |
Correct |
3 ms |
5468 KB |
Output is correct |
73 |
Correct |
2 ms |
5464 KB |
Output is correct |
74 |
Correct |
3 ms |
5364 KB |
Output is correct |
75 |
Correct |
3 ms |
5464 KB |
Output is correct |
76 |
Correct |
2 ms |
5464 KB |
Output is correct |
77 |
Correct |
2 ms |
5468 KB |
Output is correct |
78 |
Correct |
2 ms |
5468 KB |
Output is correct |
79 |
Correct |
2 ms |
5468 KB |
Output is correct |
80 |
Correct |
41 ms |
11444 KB |
Output is correct |
81 |
Correct |
46 ms |
11568 KB |
Output is correct |
82 |
Correct |
40 ms |
11244 KB |
Output is correct |
83 |
Correct |
40 ms |
10996 KB |
Output is correct |
84 |
Correct |
2 ms |
5468 KB |
Output is correct |
85 |
Correct |
2 ms |
5468 KB |
Output is correct |
86 |
Correct |
2 ms |
5468 KB |
Output is correct |
87 |
Correct |
2 ms |
5468 KB |
Output is correct |
88 |
Correct |
2 ms |
5468 KB |
Output is correct |
89 |
Correct |
2 ms |
5464 KB |
Output is correct |
90 |
Correct |
2 ms |
5464 KB |
Output is correct |
91 |
Correct |
3 ms |
5472 KB |
Output is correct |
92 |
Correct |
2 ms |
5464 KB |
Output is correct |
93 |
Correct |
3 ms |
5468 KB |
Output is correct |
94 |
Correct |
2 ms |
5212 KB |
Output is correct |
95 |
Correct |
2 ms |
5212 KB |
Output is correct |
96 |
Correct |
1 ms |
5208 KB |
Output is correct |
97 |
Correct |
2 ms |
5212 KB |
Output is correct |
98 |
Correct |
1 ms |
5212 KB |
Output is correct |
99 |
Correct |
2 ms |
5208 KB |
Output is correct |
100 |
Correct |
2 ms |
5212 KB |
Output is correct |
101 |
Correct |
2 ms |
5212 KB |
Output is correct |
102 |
Correct |
1 ms |
5212 KB |
Output is correct |
103 |
Correct |
2 ms |
5208 KB |
Output is correct |
104 |
Correct |
5 ms |
5980 KB |
Output is correct |
105 |
Correct |
9 ms |
7260 KB |
Output is correct |
106 |
Correct |
2 ms |
5212 KB |
Output is correct |
107 |
Correct |
36 ms |
8900 KB |
Output is correct |
108 |
Correct |
22 ms |
11124 KB |
Output is correct |
109 |
Correct |
3 ms |
5212 KB |
Output is correct |
110 |
Correct |
31 ms |
11840 KB |
Output is correct |
111 |
Correct |
46 ms |
12992 KB |
Output is correct |
112 |
Correct |
2 ms |
5208 KB |
Output is correct |
113 |
Correct |
65 ms |
18288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
7900 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5212 KB |
Output is correct |
2 |
Correct |
2 ms |
5212 KB |
Output is correct |
3 |
Correct |
2 ms |
5212 KB |
Output is correct |
4 |
Correct |
2 ms |
5212 KB |
Output is correct |
5 |
Correct |
2 ms |
5212 KB |
Output is correct |
6 |
Correct |
1 ms |
5212 KB |
Output is correct |
7 |
Correct |
1 ms |
5212 KB |
Output is correct |
8 |
Correct |
1 ms |
5212 KB |
Output is correct |
9 |
Correct |
2 ms |
5212 KB |
Output is correct |
10 |
Correct |
2 ms |
5212 KB |
Output is correct |
11 |
Correct |
1 ms |
5212 KB |
Output is correct |
12 |
Correct |
1 ms |
5212 KB |
Output is correct |
13 |
Correct |
1 ms |
5212 KB |
Output is correct |
14 |
Correct |
1 ms |
5212 KB |
Output is correct |
15 |
Correct |
1 ms |
5208 KB |
Output is correct |
16 |
Correct |
2 ms |
5212 KB |
Output is correct |
17 |
Correct |
1 ms |
5212 KB |
Output is correct |
18 |
Correct |
2 ms |
5212 KB |
Output is correct |
19 |
Correct |
1 ms |
5212 KB |
Output is correct |
20 |
Correct |
1 ms |
5208 KB |
Output is correct |
21 |
Correct |
1 ms |
5212 KB |
Output is correct |
22 |
Correct |
2 ms |
5212 KB |
Output is correct |
23 |
Correct |
2 ms |
5212 KB |
Output is correct |
24 |
Correct |
1 ms |
5212 KB |
Output is correct |
25 |
Correct |
1 ms |
5284 KB |
Output is correct |
26 |
Correct |
3 ms |
5208 KB |
Output is correct |
27 |
Correct |
2 ms |
5208 KB |
Output is correct |
28 |
Correct |
2 ms |
5468 KB |
Output is correct |
29 |
Incorrect |
2 ms |
5212 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
13924 KB |
Output is correct |
2 |
Correct |
43 ms |
13628 KB |
Output is correct |
3 |
Correct |
39 ms |
12412 KB |
Output is correct |
4 |
Correct |
6 ms |
6488 KB |
Output is correct |
5 |
Correct |
6 ms |
5976 KB |
Output is correct |
6 |
Correct |
10 ms |
7212 KB |
Output is correct |
7 |
Correct |
1 ms |
5212 KB |
Output is correct |
8 |
Correct |
17 ms |
9052 KB |
Output is correct |
9 |
Correct |
47 ms |
11012 KB |
Output is correct |
10 |
Correct |
2 ms |
5212 KB |
Output is correct |
11 |
Correct |
29 ms |
11600 KB |
Output is correct |
12 |
Correct |
63 ms |
12680 KB |
Output is correct |
13 |
Correct |
2 ms |
5208 KB |
Output is correct |
14 |
Correct |
2 ms |
5212 KB |
Output is correct |
15 |
Correct |
2 ms |
5212 KB |
Output is correct |
16 |
Correct |
2 ms |
5212 KB |
Output is correct |
17 |
Correct |
2 ms |
5212 KB |
Output is correct |
18 |
Correct |
2 ms |
5212 KB |
Output is correct |
19 |
Correct |
1 ms |
5212 KB |
Output is correct |
20 |
Correct |
1 ms |
5212 KB |
Output is correct |
21 |
Correct |
1 ms |
5212 KB |
Output is correct |
22 |
Correct |
2 ms |
5212 KB |
Output is correct |
23 |
Correct |
2 ms |
5212 KB |
Output is correct |
24 |
Correct |
1 ms |
5212 KB |
Output is correct |
25 |
Correct |
1 ms |
5212 KB |
Output is correct |
26 |
Correct |
1 ms |
5212 KB |
Output is correct |
27 |
Correct |
1 ms |
5212 KB |
Output is correct |
28 |
Correct |
1 ms |
5208 KB |
Output is correct |
29 |
Correct |
2 ms |
5212 KB |
Output is correct |
30 |
Correct |
1 ms |
5212 KB |
Output is correct |
31 |
Correct |
2 ms |
5212 KB |
Output is correct |
32 |
Correct |
1 ms |
5212 KB |
Output is correct |
33 |
Correct |
1 ms |
5208 KB |
Output is correct |
34 |
Correct |
1 ms |
5212 KB |
Output is correct |
35 |
Correct |
2 ms |
5212 KB |
Output is correct |
36 |
Correct |
2 ms |
5212 KB |
Output is correct |
37 |
Correct |
1 ms |
5212 KB |
Output is correct |
38 |
Correct |
1 ms |
5284 KB |
Output is correct |
39 |
Correct |
61 ms |
13836 KB |
Output is correct |
40 |
Correct |
37 ms |
13596 KB |
Output is correct |
41 |
Correct |
25 ms |
12628 KB |
Output is correct |
42 |
Correct |
6 ms |
6488 KB |
Output is correct |
43 |
Correct |
1 ms |
5212 KB |
Output is correct |
44 |
Correct |
1 ms |
5208 KB |
Output is correct |
45 |
Correct |
1 ms |
5212 KB |
Output is correct |
46 |
Correct |
1 ms |
5212 KB |
Output is correct |
47 |
Correct |
2 ms |
5212 KB |
Output is correct |
48 |
Correct |
1 ms |
5208 KB |
Output is correct |
49 |
Correct |
2 ms |
5208 KB |
Output is correct |
50 |
Correct |
1 ms |
5208 KB |
Output is correct |
51 |
Correct |
1 ms |
5212 KB |
Output is correct |
52 |
Correct |
2 ms |
5212 KB |
Output is correct |
53 |
Correct |
1 ms |
5212 KB |
Output is correct |
54 |
Correct |
2 ms |
5212 KB |
Output is correct |
55 |
Correct |
2 ms |
5212 KB |
Output is correct |
56 |
Correct |
2 ms |
5208 KB |
Output is correct |
57 |
Correct |
47 ms |
11816 KB |
Output is correct |
58 |
Correct |
42 ms |
11704 KB |
Output is correct |
59 |
Correct |
52 ms |
11260 KB |
Output is correct |
60 |
Correct |
71 ms |
11364 KB |
Output is correct |
61 |
Correct |
72 ms |
11144 KB |
Output is correct |
62 |
Correct |
51 ms |
11196 KB |
Output is correct |
63 |
Correct |
68 ms |
11012 KB |
Output is correct |
64 |
Correct |
74 ms |
10924 KB |
Output is correct |
65 |
Correct |
68 ms |
11176 KB |
Output is correct |
66 |
Correct |
48 ms |
11224 KB |
Output is correct |
67 |
Correct |
44 ms |
11552 KB |
Output is correct |
68 |
Correct |
49 ms |
11336 KB |
Output is correct |
69 |
Correct |
51 ms |
11600 KB |
Output is correct |
70 |
Correct |
72 ms |
11392 KB |
Output is correct |
71 |
Correct |
1 ms |
5212 KB |
Output is correct |
72 |
Correct |
3 ms |
5468 KB |
Output is correct |
73 |
Correct |
2 ms |
5464 KB |
Output is correct |
74 |
Correct |
3 ms |
5364 KB |
Output is correct |
75 |
Correct |
3 ms |
5464 KB |
Output is correct |
76 |
Correct |
2 ms |
5464 KB |
Output is correct |
77 |
Correct |
2 ms |
5468 KB |
Output is correct |
78 |
Correct |
2 ms |
5468 KB |
Output is correct |
79 |
Correct |
2 ms |
5468 KB |
Output is correct |
80 |
Correct |
41 ms |
11444 KB |
Output is correct |
81 |
Correct |
46 ms |
11568 KB |
Output is correct |
82 |
Correct |
40 ms |
11244 KB |
Output is correct |
83 |
Correct |
40 ms |
10996 KB |
Output is correct |
84 |
Correct |
2 ms |
5468 KB |
Output is correct |
85 |
Correct |
2 ms |
5468 KB |
Output is correct |
86 |
Correct |
2 ms |
5468 KB |
Output is correct |
87 |
Correct |
2 ms |
5468 KB |
Output is correct |
88 |
Correct |
2 ms |
5468 KB |
Output is correct |
89 |
Correct |
2 ms |
5464 KB |
Output is correct |
90 |
Correct |
2 ms |
5464 KB |
Output is correct |
91 |
Correct |
3 ms |
5472 KB |
Output is correct |
92 |
Correct |
2 ms |
5464 KB |
Output is correct |
93 |
Correct |
3 ms |
5468 KB |
Output is correct |
94 |
Correct |
2 ms |
5212 KB |
Output is correct |
95 |
Correct |
2 ms |
5212 KB |
Output is correct |
96 |
Correct |
1 ms |
5208 KB |
Output is correct |
97 |
Correct |
2 ms |
5212 KB |
Output is correct |
98 |
Correct |
1 ms |
5212 KB |
Output is correct |
99 |
Correct |
2 ms |
5208 KB |
Output is correct |
100 |
Correct |
2 ms |
5212 KB |
Output is correct |
101 |
Correct |
2 ms |
5212 KB |
Output is correct |
102 |
Correct |
1 ms |
5212 KB |
Output is correct |
103 |
Correct |
2 ms |
5208 KB |
Output is correct |
104 |
Correct |
5 ms |
5980 KB |
Output is correct |
105 |
Correct |
9 ms |
7260 KB |
Output is correct |
106 |
Correct |
2 ms |
5212 KB |
Output is correct |
107 |
Correct |
36 ms |
8900 KB |
Output is correct |
108 |
Correct |
22 ms |
11124 KB |
Output is correct |
109 |
Correct |
3 ms |
5212 KB |
Output is correct |
110 |
Correct |
31 ms |
11840 KB |
Output is correct |
111 |
Correct |
46 ms |
12992 KB |
Output is correct |
112 |
Correct |
2 ms |
5208 KB |
Output is correct |
113 |
Correct |
65 ms |
18288 KB |
Output is correct |
114 |
Incorrect |
17 ms |
7900 KB |
Output isn't correct |
115 |
Halted |
0 ms |
0 KB |
- |