#include "dreaming.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
int u[N], dw[N], up[N], ans, mx;
vector < pair <int, int> > g[N];
void dfs(int v, int pr){
u[v] = 1;
int mx1 = 0, mx2 = 0;
for(int i = 0; i < (int)g[v].size(); i ++){
int to = g[v][i].first, len = g[v][i].second;
if(to == pr)
continue;
dfs(to, v);
dw[v] = max(dw[v], dw[to] + len);
if(mx1 < dw[to] + len)
mx2 = mx1, mx1 = dw[to] + len;
else
mx2 = max(mx2, dw[to] + len);
}
ans = max(ans, mx1 + mx2);
}
void dfs1(int v, int pr){
mx = min(mx, max(up[v], dw[v]));
vector < pair <int, int> > vec;
for(int i = 0; i < (int)g[v].size(); i ++){
int to = g[v][i].first, len = g[v][i].second;
if(to == pr) continue;
vec.push_back( {dw[to] + len, to} );
}
sort(vec.rbegin(), vec.rend());
for(int i = 0; i < (int)g[v].size(); i ++){
int to = g[v][i].first, len = g[v][i].second;
if(to == pr)
continue;
up[to] = max(up[to], up[v] + len);
if(to == vec[0].second){
if((int)vec.size() > 1)
up[to] = max(up[to], vec[1].first + len);
} else {
up[to] = max(up[to], vec[0].first + len);
}
dfs1(to, v);
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for(int i = 0; i < M; i ++){
int u = A[i], v = B[i], w = T[i];
g[u].push_back( {v, w} );
g[v].push_back( {u, w} );
}
vector <int> vec;
for(int i = 0; i < N; i ++){
if(!u[i]){
mx = 2e9;
dfs(i, -1);
dfs1(i, -1);
vec.push_back(mx);
}
}
sort(vec.rbegin(), vec.rend());
if((int)vec.size() > 1)
ans = max(ans, vec[0] + vec[1] + L);
if((int)vec.size() > 2)
ans = max(ans, vec[1] + vec[1] + L + L);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
17016 KB |
Output is correct |
2 |
Correct |
77 ms |
16248 KB |
Output is correct |
3 |
Correct |
58 ms |
14960 KB |
Output is correct |
4 |
Correct |
14 ms |
4728 KB |
Output is correct |
5 |
Correct |
12 ms |
3832 KB |
Output is correct |
6 |
Correct |
21 ms |
5880 KB |
Output is correct |
7 |
Correct |
4 ms |
2808 KB |
Output is correct |
8 |
Correct |
39 ms |
8568 KB |
Output is correct |
9 |
Correct |
50 ms |
12152 KB |
Output is correct |
10 |
Correct |
4 ms |
2808 KB |
Output is correct |
11 |
Correct |
73 ms |
12920 KB |
Output is correct |
12 |
Correct |
86 ms |
14712 KB |
Output is correct |
13 |
Correct |
5 ms |
2808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
17016 KB |
Output is correct |
2 |
Correct |
77 ms |
16248 KB |
Output is correct |
3 |
Correct |
58 ms |
14960 KB |
Output is correct |
4 |
Correct |
14 ms |
4728 KB |
Output is correct |
5 |
Correct |
12 ms |
3832 KB |
Output is correct |
6 |
Correct |
21 ms |
5880 KB |
Output is correct |
7 |
Correct |
4 ms |
2808 KB |
Output is correct |
8 |
Correct |
39 ms |
8568 KB |
Output is correct |
9 |
Correct |
50 ms |
12152 KB |
Output is correct |
10 |
Correct |
4 ms |
2808 KB |
Output is correct |
11 |
Correct |
73 ms |
12920 KB |
Output is correct |
12 |
Correct |
86 ms |
14712 KB |
Output is correct |
13 |
Correct |
5 ms |
2808 KB |
Output is correct |
14 |
Correct |
4 ms |
2680 KB |
Output is correct |
15 |
Correct |
4 ms |
2684 KB |
Output is correct |
16 |
Correct |
4 ms |
2680 KB |
Output is correct |
17 |
Correct |
4 ms |
2692 KB |
Output is correct |
18 |
Correct |
4 ms |
2680 KB |
Output is correct |
19 |
Correct |
4 ms |
2680 KB |
Output is correct |
20 |
Correct |
4 ms |
2680 KB |
Output is correct |
21 |
Correct |
4 ms |
2680 KB |
Output is correct |
22 |
Correct |
4 ms |
2680 KB |
Output is correct |
23 |
Correct |
4 ms |
2680 KB |
Output is correct |
24 |
Correct |
4 ms |
2680 KB |
Output is correct |
25 |
Correct |
4 ms |
2680 KB |
Output is correct |
26 |
Correct |
4 ms |
2680 KB |
Output is correct |
27 |
Correct |
4 ms |
2672 KB |
Output is correct |
28 |
Correct |
4 ms |
2680 KB |
Output is correct |
29 |
Correct |
4 ms |
2684 KB |
Output is correct |
30 |
Correct |
4 ms |
2680 KB |
Output is correct |
31 |
Correct |
4 ms |
2680 KB |
Output is correct |
32 |
Correct |
4 ms |
2680 KB |
Output is correct |
33 |
Correct |
4 ms |
2680 KB |
Output is correct |
34 |
Correct |
4 ms |
2680 KB |
Output is correct |
35 |
Correct |
4 ms |
2680 KB |
Output is correct |
36 |
Correct |
4 ms |
2680 KB |
Output is correct |
37 |
Correct |
4 ms |
2684 KB |
Output is correct |
38 |
Correct |
4 ms |
2680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
17016 KB |
Output is correct |
2 |
Correct |
77 ms |
16248 KB |
Output is correct |
3 |
Correct |
58 ms |
14960 KB |
Output is correct |
4 |
Correct |
14 ms |
4728 KB |
Output is correct |
5 |
Correct |
12 ms |
3832 KB |
Output is correct |
6 |
Correct |
21 ms |
5880 KB |
Output is correct |
7 |
Correct |
4 ms |
2808 KB |
Output is correct |
8 |
Correct |
39 ms |
8568 KB |
Output is correct |
9 |
Correct |
50 ms |
12152 KB |
Output is correct |
10 |
Correct |
4 ms |
2808 KB |
Output is correct |
11 |
Correct |
73 ms |
12920 KB |
Output is correct |
12 |
Correct |
86 ms |
14712 KB |
Output is correct |
13 |
Correct |
5 ms |
2808 KB |
Output is correct |
14 |
Correct |
4 ms |
2680 KB |
Output is correct |
15 |
Correct |
4 ms |
2684 KB |
Output is correct |
16 |
Correct |
4 ms |
2680 KB |
Output is correct |
17 |
Correct |
4 ms |
2692 KB |
Output is correct |
18 |
Correct |
4 ms |
2680 KB |
Output is correct |
19 |
Correct |
4 ms |
2680 KB |
Output is correct |
20 |
Correct |
4 ms |
2680 KB |
Output is correct |
21 |
Correct |
4 ms |
2680 KB |
Output is correct |
22 |
Correct |
4 ms |
2680 KB |
Output is correct |
23 |
Correct |
4 ms |
2680 KB |
Output is correct |
24 |
Correct |
4 ms |
2680 KB |
Output is correct |
25 |
Correct |
4 ms |
2680 KB |
Output is correct |
26 |
Correct |
4 ms |
2680 KB |
Output is correct |
27 |
Correct |
4 ms |
2672 KB |
Output is correct |
28 |
Correct |
4 ms |
2680 KB |
Output is correct |
29 |
Correct |
4 ms |
2684 KB |
Output is correct |
30 |
Correct |
4 ms |
2680 KB |
Output is correct |
31 |
Correct |
4 ms |
2680 KB |
Output is correct |
32 |
Correct |
4 ms |
2680 KB |
Output is correct |
33 |
Correct |
4 ms |
2680 KB |
Output is correct |
34 |
Correct |
4 ms |
2680 KB |
Output is correct |
35 |
Correct |
4 ms |
2680 KB |
Output is correct |
36 |
Correct |
4 ms |
2680 KB |
Output is correct |
37 |
Correct |
4 ms |
2684 KB |
Output is correct |
38 |
Correct |
4 ms |
2680 KB |
Output is correct |
39 |
Correct |
84 ms |
16888 KB |
Output is correct |
40 |
Correct |
83 ms |
16240 KB |
Output is correct |
41 |
Correct |
56 ms |
14940 KB |
Output is correct |
42 |
Correct |
14 ms |
4728 KB |
Output is correct |
43 |
Correct |
4 ms |
2680 KB |
Output is correct |
44 |
Correct |
4 ms |
2680 KB |
Output is correct |
45 |
Correct |
5 ms |
2680 KB |
Output is correct |
46 |
Correct |
4 ms |
2680 KB |
Output is correct |
47 |
Correct |
4 ms |
2680 KB |
Output is correct |
48 |
Correct |
4 ms |
2760 KB |
Output is correct |
49 |
Correct |
4 ms |
2680 KB |
Output is correct |
50 |
Correct |
4 ms |
2728 KB |
Output is correct |
51 |
Correct |
4 ms |
2680 KB |
Output is correct |
52 |
Correct |
4 ms |
2680 KB |
Output is correct |
53 |
Correct |
4 ms |
2680 KB |
Output is correct |
54 |
Correct |
4 ms |
2680 KB |
Output is correct |
55 |
Correct |
4 ms |
2680 KB |
Output is correct |
56 |
Correct |
4 ms |
2680 KB |
Output is correct |
57 |
Correct |
104 ms |
10464 KB |
Output is correct |
58 |
Correct |
93 ms |
10488 KB |
Output is correct |
59 |
Correct |
95 ms |
10488 KB |
Output is correct |
60 |
Correct |
97 ms |
10360 KB |
Output is correct |
61 |
Correct |
100 ms |
10360 KB |
Output is correct |
62 |
Correct |
98 ms |
10360 KB |
Output is correct |
63 |
Correct |
103 ms |
10104 KB |
Output is correct |
64 |
Correct |
101 ms |
10204 KB |
Output is correct |
65 |
Correct |
105 ms |
10360 KB |
Output is correct |
66 |
Correct |
87 ms |
10360 KB |
Output is correct |
67 |
Correct |
97 ms |
10360 KB |
Output is correct |
68 |
Correct |
88 ms |
10360 KB |
Output is correct |
69 |
Correct |
101 ms |
10784 KB |
Output is correct |
70 |
Correct |
107 ms |
10608 KB |
Output is correct |
71 |
Correct |
4 ms |
2808 KB |
Output is correct |
72 |
Correct |
6 ms |
2936 KB |
Output is correct |
73 |
Correct |
6 ms |
2936 KB |
Output is correct |
74 |
Correct |
6 ms |
2936 KB |
Output is correct |
75 |
Correct |
6 ms |
2936 KB |
Output is correct |
76 |
Correct |
6 ms |
2936 KB |
Output is correct |
77 |
Correct |
6 ms |
2936 KB |
Output is correct |
78 |
Correct |
6 ms |
2936 KB |
Output is correct |
79 |
Correct |
6 ms |
2936 KB |
Output is correct |
80 |
Correct |
125 ms |
10492 KB |
Output is correct |
81 |
Correct |
87 ms |
10360 KB |
Output is correct |
82 |
Correct |
118 ms |
10488 KB |
Output is correct |
83 |
Correct |
95 ms |
10360 KB |
Output is correct |
84 |
Correct |
5 ms |
2936 KB |
Output is correct |
85 |
Correct |
5 ms |
2940 KB |
Output is correct |
86 |
Correct |
6 ms |
2808 KB |
Output is correct |
87 |
Correct |
6 ms |
2936 KB |
Output is correct |
88 |
Correct |
6 ms |
2936 KB |
Output is correct |
89 |
Correct |
6 ms |
2936 KB |
Output is correct |
90 |
Correct |
7 ms |
2936 KB |
Output is correct |
91 |
Correct |
6 ms |
2936 KB |
Output is correct |
92 |
Correct |
6 ms |
2936 KB |
Output is correct |
93 |
Correct |
6 ms |
2936 KB |
Output is correct |
94 |
Correct |
4 ms |
2680 KB |
Output is correct |
95 |
Correct |
4 ms |
2680 KB |
Output is correct |
96 |
Correct |
4 ms |
2756 KB |
Output is correct |
97 |
Correct |
4 ms |
2680 KB |
Output is correct |
98 |
Correct |
4 ms |
2680 KB |
Output is correct |
99 |
Correct |
4 ms |
2680 KB |
Output is correct |
100 |
Correct |
4 ms |
2680 KB |
Output is correct |
101 |
Correct |
4 ms |
2680 KB |
Output is correct |
102 |
Correct |
4 ms |
2680 KB |
Output is correct |
103 |
Correct |
4 ms |
2680 KB |
Output is correct |
104 |
Correct |
12 ms |
3832 KB |
Output is correct |
105 |
Correct |
22 ms |
5880 KB |
Output is correct |
106 |
Correct |
4 ms |
2808 KB |
Output is correct |
107 |
Correct |
40 ms |
8440 KB |
Output is correct |
108 |
Correct |
52 ms |
12280 KB |
Output is correct |
109 |
Correct |
5 ms |
2808 KB |
Output is correct |
110 |
Correct |
73 ms |
12792 KB |
Output is correct |
111 |
Correct |
91 ms |
14740 KB |
Output is correct |
112 |
Correct |
5 ms |
2808 KB |
Output is correct |
113 |
Correct |
142 ms |
25204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
6904 KB |
Output is correct |
2 |
Incorrect |
34 ms |
6904 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
17016 KB |
Output is correct |
2 |
Correct |
77 ms |
16248 KB |
Output is correct |
3 |
Correct |
58 ms |
14960 KB |
Output is correct |
4 |
Correct |
14 ms |
4728 KB |
Output is correct |
5 |
Correct |
12 ms |
3832 KB |
Output is correct |
6 |
Correct |
21 ms |
5880 KB |
Output is correct |
7 |
Correct |
4 ms |
2808 KB |
Output is correct |
8 |
Correct |
39 ms |
8568 KB |
Output is correct |
9 |
Correct |
50 ms |
12152 KB |
Output is correct |
10 |
Correct |
4 ms |
2808 KB |
Output is correct |
11 |
Correct |
73 ms |
12920 KB |
Output is correct |
12 |
Correct |
86 ms |
14712 KB |
Output is correct |
13 |
Correct |
5 ms |
2808 KB |
Output is correct |
14 |
Correct |
5 ms |
2808 KB |
Output is correct |
15 |
Correct |
5 ms |
2808 KB |
Output is correct |
16 |
Correct |
6 ms |
2936 KB |
Output is correct |
17 |
Incorrect |
5 ms |
2808 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
17016 KB |
Output is correct |
2 |
Correct |
77 ms |
16248 KB |
Output is correct |
3 |
Correct |
58 ms |
14960 KB |
Output is correct |
4 |
Correct |
14 ms |
4728 KB |
Output is correct |
5 |
Correct |
12 ms |
3832 KB |
Output is correct |
6 |
Correct |
21 ms |
5880 KB |
Output is correct |
7 |
Correct |
4 ms |
2808 KB |
Output is correct |
8 |
Correct |
39 ms |
8568 KB |
Output is correct |
9 |
Correct |
50 ms |
12152 KB |
Output is correct |
10 |
Correct |
4 ms |
2808 KB |
Output is correct |
11 |
Correct |
73 ms |
12920 KB |
Output is correct |
12 |
Correct |
86 ms |
14712 KB |
Output is correct |
13 |
Correct |
5 ms |
2808 KB |
Output is correct |
14 |
Correct |
4 ms |
2680 KB |
Output is correct |
15 |
Correct |
4 ms |
2684 KB |
Output is correct |
16 |
Correct |
4 ms |
2680 KB |
Output is correct |
17 |
Correct |
4 ms |
2692 KB |
Output is correct |
18 |
Correct |
4 ms |
2680 KB |
Output is correct |
19 |
Correct |
4 ms |
2680 KB |
Output is correct |
20 |
Correct |
4 ms |
2680 KB |
Output is correct |
21 |
Correct |
4 ms |
2680 KB |
Output is correct |
22 |
Correct |
4 ms |
2680 KB |
Output is correct |
23 |
Correct |
4 ms |
2680 KB |
Output is correct |
24 |
Correct |
4 ms |
2680 KB |
Output is correct |
25 |
Correct |
4 ms |
2680 KB |
Output is correct |
26 |
Correct |
4 ms |
2680 KB |
Output is correct |
27 |
Correct |
4 ms |
2672 KB |
Output is correct |
28 |
Correct |
4 ms |
2680 KB |
Output is correct |
29 |
Correct |
4 ms |
2684 KB |
Output is correct |
30 |
Correct |
4 ms |
2680 KB |
Output is correct |
31 |
Correct |
4 ms |
2680 KB |
Output is correct |
32 |
Correct |
4 ms |
2680 KB |
Output is correct |
33 |
Correct |
4 ms |
2680 KB |
Output is correct |
34 |
Correct |
4 ms |
2680 KB |
Output is correct |
35 |
Correct |
4 ms |
2680 KB |
Output is correct |
36 |
Correct |
4 ms |
2680 KB |
Output is correct |
37 |
Correct |
4 ms |
2684 KB |
Output is correct |
38 |
Correct |
4 ms |
2680 KB |
Output is correct |
39 |
Correct |
84 ms |
16888 KB |
Output is correct |
40 |
Correct |
83 ms |
16240 KB |
Output is correct |
41 |
Correct |
56 ms |
14940 KB |
Output is correct |
42 |
Correct |
14 ms |
4728 KB |
Output is correct |
43 |
Correct |
4 ms |
2680 KB |
Output is correct |
44 |
Correct |
4 ms |
2680 KB |
Output is correct |
45 |
Correct |
5 ms |
2680 KB |
Output is correct |
46 |
Correct |
4 ms |
2680 KB |
Output is correct |
47 |
Correct |
4 ms |
2680 KB |
Output is correct |
48 |
Correct |
4 ms |
2760 KB |
Output is correct |
49 |
Correct |
4 ms |
2680 KB |
Output is correct |
50 |
Correct |
4 ms |
2728 KB |
Output is correct |
51 |
Correct |
4 ms |
2680 KB |
Output is correct |
52 |
Correct |
4 ms |
2680 KB |
Output is correct |
53 |
Correct |
4 ms |
2680 KB |
Output is correct |
54 |
Correct |
4 ms |
2680 KB |
Output is correct |
55 |
Correct |
4 ms |
2680 KB |
Output is correct |
56 |
Correct |
4 ms |
2680 KB |
Output is correct |
57 |
Correct |
104 ms |
10464 KB |
Output is correct |
58 |
Correct |
93 ms |
10488 KB |
Output is correct |
59 |
Correct |
95 ms |
10488 KB |
Output is correct |
60 |
Correct |
97 ms |
10360 KB |
Output is correct |
61 |
Correct |
100 ms |
10360 KB |
Output is correct |
62 |
Correct |
98 ms |
10360 KB |
Output is correct |
63 |
Correct |
103 ms |
10104 KB |
Output is correct |
64 |
Correct |
101 ms |
10204 KB |
Output is correct |
65 |
Correct |
105 ms |
10360 KB |
Output is correct |
66 |
Correct |
87 ms |
10360 KB |
Output is correct |
67 |
Correct |
97 ms |
10360 KB |
Output is correct |
68 |
Correct |
88 ms |
10360 KB |
Output is correct |
69 |
Correct |
101 ms |
10784 KB |
Output is correct |
70 |
Correct |
107 ms |
10608 KB |
Output is correct |
71 |
Correct |
4 ms |
2808 KB |
Output is correct |
72 |
Correct |
6 ms |
2936 KB |
Output is correct |
73 |
Correct |
6 ms |
2936 KB |
Output is correct |
74 |
Correct |
6 ms |
2936 KB |
Output is correct |
75 |
Correct |
6 ms |
2936 KB |
Output is correct |
76 |
Correct |
6 ms |
2936 KB |
Output is correct |
77 |
Correct |
6 ms |
2936 KB |
Output is correct |
78 |
Correct |
6 ms |
2936 KB |
Output is correct |
79 |
Correct |
6 ms |
2936 KB |
Output is correct |
80 |
Correct |
125 ms |
10492 KB |
Output is correct |
81 |
Correct |
87 ms |
10360 KB |
Output is correct |
82 |
Correct |
118 ms |
10488 KB |
Output is correct |
83 |
Correct |
95 ms |
10360 KB |
Output is correct |
84 |
Correct |
5 ms |
2936 KB |
Output is correct |
85 |
Correct |
5 ms |
2940 KB |
Output is correct |
86 |
Correct |
6 ms |
2808 KB |
Output is correct |
87 |
Correct |
6 ms |
2936 KB |
Output is correct |
88 |
Correct |
6 ms |
2936 KB |
Output is correct |
89 |
Correct |
6 ms |
2936 KB |
Output is correct |
90 |
Correct |
7 ms |
2936 KB |
Output is correct |
91 |
Correct |
6 ms |
2936 KB |
Output is correct |
92 |
Correct |
6 ms |
2936 KB |
Output is correct |
93 |
Correct |
6 ms |
2936 KB |
Output is correct |
94 |
Correct |
4 ms |
2680 KB |
Output is correct |
95 |
Correct |
4 ms |
2680 KB |
Output is correct |
96 |
Correct |
4 ms |
2756 KB |
Output is correct |
97 |
Correct |
4 ms |
2680 KB |
Output is correct |
98 |
Correct |
4 ms |
2680 KB |
Output is correct |
99 |
Correct |
4 ms |
2680 KB |
Output is correct |
100 |
Correct |
4 ms |
2680 KB |
Output is correct |
101 |
Correct |
4 ms |
2680 KB |
Output is correct |
102 |
Correct |
4 ms |
2680 KB |
Output is correct |
103 |
Correct |
4 ms |
2680 KB |
Output is correct |
104 |
Correct |
12 ms |
3832 KB |
Output is correct |
105 |
Correct |
22 ms |
5880 KB |
Output is correct |
106 |
Correct |
4 ms |
2808 KB |
Output is correct |
107 |
Correct |
40 ms |
8440 KB |
Output is correct |
108 |
Correct |
52 ms |
12280 KB |
Output is correct |
109 |
Correct |
5 ms |
2808 KB |
Output is correct |
110 |
Correct |
73 ms |
12792 KB |
Output is correct |
111 |
Correct |
91 ms |
14740 KB |
Output is correct |
112 |
Correct |
5 ms |
2808 KB |
Output is correct |
113 |
Correct |
142 ms |
25204 KB |
Output is correct |
114 |
Correct |
36 ms |
6904 KB |
Output is correct |
115 |
Incorrect |
34 ms |
6904 KB |
Output isn't correct |
116 |
Halted |
0 ms |
0 KB |
- |