#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),
up[to] = max(up[to], up[v] + len);
} else {
up[to] = max(up[to], vec[0].first + len),
up[to] = max(up[to], up[v] + 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);
return ans;
}
/**
12 8 2
0 8 4
8 2 2
2 7 4
5 11 3
5 1 7
1 3 1
1 9 5
10 6 3
**/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
15608 KB |
Output is correct |
2 |
Correct |
81 ms |
14968 KB |
Output is correct |
3 |
Correct |
57 ms |
13948 KB |
Output is correct |
4 |
Correct |
14 ms |
4472 KB |
Output is correct |
5 |
Correct |
12 ms |
3704 KB |
Output is correct |
6 |
Correct |
22 ms |
5500 KB |
Output is correct |
7 |
Correct |
4 ms |
2808 KB |
Output is correct |
8 |
Correct |
38 ms |
8440 KB |
Output is correct |
9 |
Correct |
50 ms |
12280 KB |
Output is correct |
10 |
Correct |
4 ms |
2808 KB |
Output is correct |
11 |
Correct |
69 ms |
12920 KB |
Output is correct |
12 |
Correct |
110 ms |
14708 KB |
Output is correct |
13 |
Correct |
5 ms |
2808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
15608 KB |
Output is correct |
2 |
Correct |
81 ms |
14968 KB |
Output is correct |
3 |
Correct |
57 ms |
13948 KB |
Output is correct |
4 |
Correct |
14 ms |
4472 KB |
Output is correct |
5 |
Correct |
12 ms |
3704 KB |
Output is correct |
6 |
Correct |
22 ms |
5500 KB |
Output is correct |
7 |
Correct |
4 ms |
2808 KB |
Output is correct |
8 |
Correct |
38 ms |
8440 KB |
Output is correct |
9 |
Correct |
50 ms |
12280 KB |
Output is correct |
10 |
Correct |
4 ms |
2808 KB |
Output is correct |
11 |
Correct |
69 ms |
12920 KB |
Output is correct |
12 |
Correct |
110 ms |
14708 KB |
Output is correct |
13 |
Correct |
5 ms |
2808 KB |
Output is correct |
14 |
Correct |
4 ms |
2684 KB |
Output is correct |
15 |
Correct |
4 ms |
2680 KB |
Output is correct |
16 |
Correct |
4 ms |
2724 KB |
Output is correct |
17 |
Correct |
4 ms |
2684 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 |
5 ms |
2808 KB |
Output is correct |
22 |
Correct |
5 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 |
2684 KB |
Output is correct |
26 |
Correct |
5 ms |
2728 KB |
Output is correct |
27 |
Correct |
4 ms |
2680 KB |
Output is correct |
28 |
Correct |
4 ms |
2680 KB |
Output is correct |
29 |
Correct |
5 ms |
2680 KB |
Output is correct |
30 |
Correct |
4 ms |
2680 KB |
Output is correct |
31 |
Correct |
4 ms |
2680 KB |
Output is correct |
32 |
Correct |
5 ms |
2680 KB |
Output is correct |
33 |
Correct |
4 ms |
2680 KB |
Output is correct |
34 |
Correct |
4 ms |
2808 KB |
Output is correct |
35 |
Correct |
5 ms |
2680 KB |
Output is correct |
36 |
Correct |
4 ms |
2680 KB |
Output is correct |
37 |
Correct |
4 ms |
2680 KB |
Output is correct |
38 |
Correct |
4 ms |
2680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
15608 KB |
Output is correct |
2 |
Correct |
81 ms |
14968 KB |
Output is correct |
3 |
Correct |
57 ms |
13948 KB |
Output is correct |
4 |
Correct |
14 ms |
4472 KB |
Output is correct |
5 |
Correct |
12 ms |
3704 KB |
Output is correct |
6 |
Correct |
22 ms |
5500 KB |
Output is correct |
7 |
Correct |
4 ms |
2808 KB |
Output is correct |
8 |
Correct |
38 ms |
8440 KB |
Output is correct |
9 |
Correct |
50 ms |
12280 KB |
Output is correct |
10 |
Correct |
4 ms |
2808 KB |
Output is correct |
11 |
Correct |
69 ms |
12920 KB |
Output is correct |
12 |
Correct |
110 ms |
14708 KB |
Output is correct |
13 |
Correct |
5 ms |
2808 KB |
Output is correct |
14 |
Correct |
4 ms |
2684 KB |
Output is correct |
15 |
Correct |
4 ms |
2680 KB |
Output is correct |
16 |
Correct |
4 ms |
2724 KB |
Output is correct |
17 |
Correct |
4 ms |
2684 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 |
5 ms |
2808 KB |
Output is correct |
22 |
Correct |
5 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 |
2684 KB |
Output is correct |
26 |
Correct |
5 ms |
2728 KB |
Output is correct |
27 |
Correct |
4 ms |
2680 KB |
Output is correct |
28 |
Correct |
4 ms |
2680 KB |
Output is correct |
29 |
Correct |
5 ms |
2680 KB |
Output is correct |
30 |
Correct |
4 ms |
2680 KB |
Output is correct |
31 |
Correct |
4 ms |
2680 KB |
Output is correct |
32 |
Correct |
5 ms |
2680 KB |
Output is correct |
33 |
Correct |
4 ms |
2680 KB |
Output is correct |
34 |
Correct |
4 ms |
2808 KB |
Output is correct |
35 |
Correct |
5 ms |
2680 KB |
Output is correct |
36 |
Correct |
4 ms |
2680 KB |
Output is correct |
37 |
Correct |
4 ms |
2680 KB |
Output is correct |
38 |
Correct |
4 ms |
2680 KB |
Output is correct |
39 |
Correct |
79 ms |
16888 KB |
Output is correct |
40 |
Correct |
81 ms |
16256 KB |
Output is correct |
41 |
Correct |
56 ms |
14932 KB |
Output is correct |
42 |
Correct |
15 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 |
4 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 |
2680 KB |
Output is correct |
49 |
Correct |
4 ms |
2684 KB |
Output is correct |
50 |
Correct |
4 ms |
2680 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 |
130 ms |
10496 KB |
Output is correct |
58 |
Correct |
122 ms |
10388 KB |
Output is correct |
59 |
Correct |
116 ms |
10488 KB |
Output is correct |
60 |
Correct |
91 ms |
10316 KB |
Output is correct |
61 |
Correct |
93 ms |
10360 KB |
Output is correct |
62 |
Correct |
132 ms |
10360 KB |
Output is correct |
63 |
Correct |
88 ms |
10104 KB |
Output is correct |
64 |
Correct |
88 ms |
9976 KB |
Output is correct |
65 |
Correct |
88 ms |
10404 KB |
Output is correct |
66 |
Correct |
89 ms |
10360 KB |
Output is correct |
67 |
Correct |
91 ms |
10360 KB |
Output is correct |
68 |
Correct |
98 ms |
10488 KB |
Output is correct |
69 |
Correct |
105 ms |
10616 KB |
Output is correct |
70 |
Correct |
96 ms |
10616 KB |
Output is correct |
71 |
Correct |
4 ms |
2680 KB |
Output is correct |
72 |
Correct |
7 ms |
2904 KB |
Output is correct |
73 |
Correct |
6 ms |
2940 KB |
Output is correct |
74 |
Correct |
6 ms |
2936 KB |
Output is correct |
75 |
Correct |
6 ms |
2940 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 |
2888 KB |
Output is correct |
79 |
Correct |
6 ms |
2936 KB |
Output is correct |
80 |
Correct |
127 ms |
10404 KB |
Output is correct |
81 |
Correct |
139 ms |
10360 KB |
Output is correct |
82 |
Correct |
96 ms |
10308 KB |
Output is correct |
83 |
Correct |
97 ms |
10424 KB |
Output is correct |
84 |
Correct |
5 ms |
2936 KB |
Output is correct |
85 |
Correct |
5 ms |
2812 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 |
6 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 |
5 ms |
2680 KB |
Output is correct |
96 |
Correct |
5 ms |
2680 KB |
Output is correct |
97 |
Correct |
4 ms |
2680 KB |
Output is correct |
98 |
Correct |
5 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 |
5792 KB |
Output is correct |
106 |
Correct |
4 ms |
2808 KB |
Output is correct |
107 |
Correct |
38 ms |
8440 KB |
Output is correct |
108 |
Correct |
54 ms |
12252 KB |
Output is correct |
109 |
Correct |
5 ms |
2808 KB |
Output is correct |
110 |
Correct |
76 ms |
12900 KB |
Output is correct |
111 |
Correct |
81 ms |
14712 KB |
Output is correct |
112 |
Correct |
5 ms |
2808 KB |
Output is correct |
113 |
Correct |
132 ms |
25336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
6520 KB |
Output is correct |
2 |
Incorrect |
35 ms |
6524 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
15608 KB |
Output is correct |
2 |
Correct |
81 ms |
14968 KB |
Output is correct |
3 |
Correct |
57 ms |
13948 KB |
Output is correct |
4 |
Correct |
14 ms |
4472 KB |
Output is correct |
5 |
Correct |
12 ms |
3704 KB |
Output is correct |
6 |
Correct |
22 ms |
5500 KB |
Output is correct |
7 |
Correct |
4 ms |
2808 KB |
Output is correct |
8 |
Correct |
38 ms |
8440 KB |
Output is correct |
9 |
Correct |
50 ms |
12280 KB |
Output is correct |
10 |
Correct |
4 ms |
2808 KB |
Output is correct |
11 |
Correct |
69 ms |
12920 KB |
Output is correct |
12 |
Correct |
110 ms |
14708 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 |
2864 KB |
Output is correct |
17 |
Correct |
5 ms |
2680 KB |
Output is correct |
18 |
Correct |
6 ms |
2808 KB |
Output is correct |
19 |
Correct |
7 ms |
2936 KB |
Output is correct |
20 |
Incorrect |
4 ms |
2680 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
15608 KB |
Output is correct |
2 |
Correct |
81 ms |
14968 KB |
Output is correct |
3 |
Correct |
57 ms |
13948 KB |
Output is correct |
4 |
Correct |
14 ms |
4472 KB |
Output is correct |
5 |
Correct |
12 ms |
3704 KB |
Output is correct |
6 |
Correct |
22 ms |
5500 KB |
Output is correct |
7 |
Correct |
4 ms |
2808 KB |
Output is correct |
8 |
Correct |
38 ms |
8440 KB |
Output is correct |
9 |
Correct |
50 ms |
12280 KB |
Output is correct |
10 |
Correct |
4 ms |
2808 KB |
Output is correct |
11 |
Correct |
69 ms |
12920 KB |
Output is correct |
12 |
Correct |
110 ms |
14708 KB |
Output is correct |
13 |
Correct |
5 ms |
2808 KB |
Output is correct |
14 |
Correct |
4 ms |
2684 KB |
Output is correct |
15 |
Correct |
4 ms |
2680 KB |
Output is correct |
16 |
Correct |
4 ms |
2724 KB |
Output is correct |
17 |
Correct |
4 ms |
2684 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 |
5 ms |
2808 KB |
Output is correct |
22 |
Correct |
5 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 |
2684 KB |
Output is correct |
26 |
Correct |
5 ms |
2728 KB |
Output is correct |
27 |
Correct |
4 ms |
2680 KB |
Output is correct |
28 |
Correct |
4 ms |
2680 KB |
Output is correct |
29 |
Correct |
5 ms |
2680 KB |
Output is correct |
30 |
Correct |
4 ms |
2680 KB |
Output is correct |
31 |
Correct |
4 ms |
2680 KB |
Output is correct |
32 |
Correct |
5 ms |
2680 KB |
Output is correct |
33 |
Correct |
4 ms |
2680 KB |
Output is correct |
34 |
Correct |
4 ms |
2808 KB |
Output is correct |
35 |
Correct |
5 ms |
2680 KB |
Output is correct |
36 |
Correct |
4 ms |
2680 KB |
Output is correct |
37 |
Correct |
4 ms |
2680 KB |
Output is correct |
38 |
Correct |
4 ms |
2680 KB |
Output is correct |
39 |
Correct |
79 ms |
16888 KB |
Output is correct |
40 |
Correct |
81 ms |
16256 KB |
Output is correct |
41 |
Correct |
56 ms |
14932 KB |
Output is correct |
42 |
Correct |
15 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 |
4 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 |
2680 KB |
Output is correct |
49 |
Correct |
4 ms |
2684 KB |
Output is correct |
50 |
Correct |
4 ms |
2680 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 |
130 ms |
10496 KB |
Output is correct |
58 |
Correct |
122 ms |
10388 KB |
Output is correct |
59 |
Correct |
116 ms |
10488 KB |
Output is correct |
60 |
Correct |
91 ms |
10316 KB |
Output is correct |
61 |
Correct |
93 ms |
10360 KB |
Output is correct |
62 |
Correct |
132 ms |
10360 KB |
Output is correct |
63 |
Correct |
88 ms |
10104 KB |
Output is correct |
64 |
Correct |
88 ms |
9976 KB |
Output is correct |
65 |
Correct |
88 ms |
10404 KB |
Output is correct |
66 |
Correct |
89 ms |
10360 KB |
Output is correct |
67 |
Correct |
91 ms |
10360 KB |
Output is correct |
68 |
Correct |
98 ms |
10488 KB |
Output is correct |
69 |
Correct |
105 ms |
10616 KB |
Output is correct |
70 |
Correct |
96 ms |
10616 KB |
Output is correct |
71 |
Correct |
4 ms |
2680 KB |
Output is correct |
72 |
Correct |
7 ms |
2904 KB |
Output is correct |
73 |
Correct |
6 ms |
2940 KB |
Output is correct |
74 |
Correct |
6 ms |
2936 KB |
Output is correct |
75 |
Correct |
6 ms |
2940 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 |
2888 KB |
Output is correct |
79 |
Correct |
6 ms |
2936 KB |
Output is correct |
80 |
Correct |
127 ms |
10404 KB |
Output is correct |
81 |
Correct |
139 ms |
10360 KB |
Output is correct |
82 |
Correct |
96 ms |
10308 KB |
Output is correct |
83 |
Correct |
97 ms |
10424 KB |
Output is correct |
84 |
Correct |
5 ms |
2936 KB |
Output is correct |
85 |
Correct |
5 ms |
2812 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 |
6 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 |
5 ms |
2680 KB |
Output is correct |
96 |
Correct |
5 ms |
2680 KB |
Output is correct |
97 |
Correct |
4 ms |
2680 KB |
Output is correct |
98 |
Correct |
5 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 |
5792 KB |
Output is correct |
106 |
Correct |
4 ms |
2808 KB |
Output is correct |
107 |
Correct |
38 ms |
8440 KB |
Output is correct |
108 |
Correct |
54 ms |
12252 KB |
Output is correct |
109 |
Correct |
5 ms |
2808 KB |
Output is correct |
110 |
Correct |
76 ms |
12900 KB |
Output is correct |
111 |
Correct |
81 ms |
14712 KB |
Output is correct |
112 |
Correct |
5 ms |
2808 KB |
Output is correct |
113 |
Correct |
132 ms |
25336 KB |
Output is correct |
114 |
Correct |
33 ms |
6520 KB |
Output is correct |
115 |
Incorrect |
35 ms |
6524 KB |
Output isn't correct |
116 |
Halted |
0 ms |
0 KB |
- |