#include "dreaming.h"
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define ll long long
using namespace std;
typedef pair<int,int> pii;
const int MAXN = 2e5+10;
const int INF = 2e9;
int n, m, l, ans;
vector <pii> adj[MAXN];
int cc[MAXN], mx[MAXN];
int dw[MAXN], up[MAXN]; // max ke bawah, ke par (atas)
void dfs(int nw, int par){
for(auto ed : adj[nw]){
int nx = ed.fi; int wei = ed.se;
dw[nw] = max(dw[nw], 0);
if(nx==par) continue;
dfs(nx, nw);
dw[nw] = max(dw[nw], dw[nx]+wei);
}
}
multiset <int> mul;
void bui(int nw, int par){
for(auto ed : adj[nw]){ // build child nya aj
int nx = ed.fi; int wei = ed.se;
if(nx==par) continue;
//build
mul.insert(dw[nx]+wei);
}
for(auto ed : adj[nw]){
int nx = ed.fi; int wei = ed.se;
if(nx==par) continue;
//build
auto it = mul.find(dw[nx]+wei);
mul.erase(it);
int mx = up[nw]; // up skrg
if(!mul.empty()){
it = mul.end(); it--;
mx = max(mx, (*it));
}
up[nx] = mx+wei; // maxnya + wei buat ke child
//cout << nx << ' '<< up[nx] << " p\n";
mul.insert(dw[nx]+wei);
}
mul.clear();
for(auto ed : adj[nw]){ // build child nya aj
int nx = ed.fi; int wei = ed.se;
if(nx==par) continue;
bui(nx, nw);
}
ans = max(ans, up[nw]);
}
int root;
void rep(int nw, int par){
cc[root] = min(cc[root], mx[nw]);
for(auto ed : adj[nw]){ // build child nya aj
int nx = ed.fi; int wei = ed.se;
if(nx==par) continue;
rep(nx, nw);
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
n = N; m = M; l = L;
for(int i=0; i<m; i++){
adj[A[i]+1].pb({B[i]+1, T[i]});
adj[B[i]+1].pb({A[i]+1, T[i]});
}
for(int i=1; i<=n; i++){
mx[i] = INF; cc[i] = INF;
}
for(int i=1; i<=n; i++){
if(up[i]!=0) continue;
dfs(i, 0);
bui(i, 0);
}
for(int i=1; i<=n; i++){
mx[i] = max(up[i], dw[i]);
}
vector <int> vec;
for(int i=1; i<=n; i++){
if(up[i]==0){
root = i;
rep(i, 0);
vec.pb(cc[i]);
}
}
//cout << vec[0] << ' ' << vec[1] << " p\n";
ans = max(ans, vec[0]+vec[1]+l);
return ans;
}
Compilation message
dreaming.cpp: In function 'void bui(int, int)':
dreaming.cpp:55:23: warning: unused variable 'wei' [-Wunused-variable]
55 | int nx = ed.fi; int wei = ed.se;
| ^~~
dreaming.cpp: In function 'void rep(int, int)':
dreaming.cpp:66:23: warning: unused variable 'wei' [-Wunused-variable]
66 | int nx = ed.fi; int wei = ed.se;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
18512 KB |
Output is correct |
2 |
Correct |
41 ms |
18000 KB |
Output is correct |
3 |
Correct |
26 ms |
17496 KB |
Output is correct |
4 |
Correct |
9 ms |
10584 KB |
Output is correct |
5 |
Correct |
7 ms |
9820 KB |
Output is correct |
6 |
Correct |
11 ms |
11100 KB |
Output is correct |
7 |
Correct |
2 ms |
9052 KB |
Output is correct |
8 |
Correct |
19 ms |
13496 KB |
Output is correct |
9 |
Correct |
31 ms |
16536 KB |
Output is correct |
10 |
Correct |
2 ms |
9308 KB |
Output is correct |
11 |
Correct |
42 ms |
16696 KB |
Output is correct |
12 |
Correct |
39 ms |
18260 KB |
Output is correct |
13 |
Correct |
2 ms |
9304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9052 KB |
Output is correct |
2 |
Correct |
2 ms |
9052 KB |
Output is correct |
3 |
Correct |
2 ms |
9048 KB |
Output is correct |
4 |
Correct |
2 ms |
9052 KB |
Output is correct |
5 |
Correct |
2 ms |
9052 KB |
Output is correct |
6 |
Correct |
3 ms |
9052 KB |
Output is correct |
7 |
Correct |
2 ms |
9052 KB |
Output is correct |
8 |
Correct |
2 ms |
9052 KB |
Output is correct |
9 |
Correct |
2 ms |
9052 KB |
Output is correct |
10 |
Correct |
2 ms |
9052 KB |
Output is correct |
11 |
Correct |
2 ms |
9052 KB |
Output is correct |
12 |
Correct |
2 ms |
9052 KB |
Output is correct |
13 |
Correct |
2 ms |
9052 KB |
Output is correct |
14 |
Correct |
2 ms |
9052 KB |
Output is correct |
15 |
Correct |
2 ms |
9144 KB |
Output is correct |
16 |
Correct |
2 ms |
9052 KB |
Output is correct |
17 |
Correct |
2 ms |
9140 KB |
Output is correct |
18 |
Correct |
2 ms |
9052 KB |
Output is correct |
19 |
Correct |
2 ms |
9052 KB |
Output is correct |
20 |
Correct |
2 ms |
9052 KB |
Output is correct |
21 |
Correct |
2 ms |
9052 KB |
Output is correct |
22 |
Correct |
2 ms |
9052 KB |
Output is correct |
23 |
Correct |
2 ms |
9052 KB |
Output is correct |
24 |
Correct |
2 ms |
9052 KB |
Output is correct |
25 |
Correct |
2 ms |
9052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
18512 KB |
Output is correct |
2 |
Correct |
41 ms |
18000 KB |
Output is correct |
3 |
Correct |
26 ms |
17496 KB |
Output is correct |
4 |
Correct |
9 ms |
10584 KB |
Output is correct |
5 |
Correct |
7 ms |
9820 KB |
Output is correct |
6 |
Correct |
11 ms |
11100 KB |
Output is correct |
7 |
Correct |
2 ms |
9052 KB |
Output is correct |
8 |
Correct |
19 ms |
13496 KB |
Output is correct |
9 |
Correct |
31 ms |
16536 KB |
Output is correct |
10 |
Correct |
2 ms |
9308 KB |
Output is correct |
11 |
Correct |
42 ms |
16696 KB |
Output is correct |
12 |
Correct |
39 ms |
18260 KB |
Output is correct |
13 |
Correct |
2 ms |
9304 KB |
Output is correct |
14 |
Correct |
2 ms |
9052 KB |
Output is correct |
15 |
Correct |
2 ms |
9052 KB |
Output is correct |
16 |
Correct |
2 ms |
9048 KB |
Output is correct |
17 |
Correct |
2 ms |
9052 KB |
Output is correct |
18 |
Correct |
2 ms |
9052 KB |
Output is correct |
19 |
Correct |
3 ms |
9052 KB |
Output is correct |
20 |
Correct |
2 ms |
9052 KB |
Output is correct |
21 |
Correct |
2 ms |
9052 KB |
Output is correct |
22 |
Correct |
2 ms |
9052 KB |
Output is correct |
23 |
Correct |
2 ms |
9052 KB |
Output is correct |
24 |
Correct |
2 ms |
9052 KB |
Output is correct |
25 |
Correct |
2 ms |
9052 KB |
Output is correct |
26 |
Correct |
2 ms |
9052 KB |
Output is correct |
27 |
Correct |
2 ms |
9052 KB |
Output is correct |
28 |
Correct |
2 ms |
9144 KB |
Output is correct |
29 |
Correct |
2 ms |
9052 KB |
Output is correct |
30 |
Correct |
2 ms |
9140 KB |
Output is correct |
31 |
Correct |
2 ms |
9052 KB |
Output is correct |
32 |
Correct |
2 ms |
9052 KB |
Output is correct |
33 |
Correct |
2 ms |
9052 KB |
Output is correct |
34 |
Correct |
2 ms |
9052 KB |
Output is correct |
35 |
Correct |
2 ms |
9052 KB |
Output is correct |
36 |
Correct |
2 ms |
9052 KB |
Output is correct |
37 |
Correct |
2 ms |
9052 KB |
Output is correct |
38 |
Correct |
2 ms |
9052 KB |
Output is correct |
39 |
Correct |
38 ms |
19792 KB |
Output is correct |
40 |
Correct |
36 ms |
19284 KB |
Output is correct |
41 |
Correct |
27 ms |
18516 KB |
Output is correct |
42 |
Correct |
7 ms |
10844 KB |
Output is correct |
43 |
Correct |
2 ms |
9052 KB |
Output is correct |
44 |
Correct |
2 ms |
9052 KB |
Output is correct |
45 |
Correct |
2 ms |
9052 KB |
Output is correct |
46 |
Correct |
2 ms |
9052 KB |
Output is correct |
47 |
Correct |
2 ms |
9052 KB |
Output is correct |
48 |
Correct |
2 ms |
9052 KB |
Output is correct |
49 |
Correct |
2 ms |
9052 KB |
Output is correct |
50 |
Correct |
2 ms |
9052 KB |
Output is correct |
51 |
Correct |
2 ms |
9052 KB |
Output is correct |
52 |
Correct |
2 ms |
9052 KB |
Output is correct |
53 |
Correct |
2 ms |
9052 KB |
Output is correct |
54 |
Correct |
2 ms |
9052 KB |
Output is correct |
55 |
Correct |
2 ms |
9048 KB |
Output is correct |
56 |
Correct |
2 ms |
9052 KB |
Output is correct |
57 |
Correct |
42 ms |
14528 KB |
Output is correct |
58 |
Correct |
42 ms |
14608 KB |
Output is correct |
59 |
Correct |
45 ms |
14684 KB |
Output is correct |
60 |
Correct |
46 ms |
14904 KB |
Output is correct |
61 |
Correct |
49 ms |
14676 KB |
Output is correct |
62 |
Correct |
44 ms |
14672 KB |
Output is correct |
63 |
Correct |
41 ms |
14416 KB |
Output is correct |
64 |
Correct |
42 ms |
14680 KB |
Output is correct |
65 |
Correct |
43 ms |
14684 KB |
Output is correct |
66 |
Correct |
44 ms |
14684 KB |
Output is correct |
67 |
Correct |
43 ms |
14672 KB |
Output is correct |
68 |
Correct |
46 ms |
14672 KB |
Output is correct |
69 |
Correct |
45 ms |
14932 KB |
Output is correct |
70 |
Correct |
51 ms |
14936 KB |
Output is correct |
71 |
Correct |
2 ms |
9052 KB |
Output is correct |
72 |
Correct |
3 ms |
9308 KB |
Output is correct |
73 |
Correct |
3 ms |
9308 KB |
Output is correct |
74 |
Correct |
3 ms |
9304 KB |
Output is correct |
75 |
Correct |
3 ms |
9304 KB |
Output is correct |
76 |
Correct |
3 ms |
9308 KB |
Output is correct |
77 |
Correct |
3 ms |
9308 KB |
Output is correct |
78 |
Correct |
3 ms |
9304 KB |
Output is correct |
79 |
Correct |
3 ms |
9308 KB |
Output is correct |
80 |
Correct |
50 ms |
14672 KB |
Output is correct |
81 |
Correct |
43 ms |
14684 KB |
Output is correct |
82 |
Correct |
45 ms |
14672 KB |
Output is correct |
83 |
Correct |
49 ms |
15184 KB |
Output is correct |
84 |
Correct |
3 ms |
9308 KB |
Output is correct |
85 |
Correct |
3 ms |
9308 KB |
Output is correct |
86 |
Correct |
3 ms |
9308 KB |
Output is correct |
87 |
Correct |
3 ms |
9308 KB |
Output is correct |
88 |
Correct |
3 ms |
9308 KB |
Output is correct |
89 |
Correct |
3 ms |
9308 KB |
Output is correct |
90 |
Correct |
3 ms |
9272 KB |
Output is correct |
91 |
Correct |
3 ms |
9272 KB |
Output is correct |
92 |
Correct |
3 ms |
9308 KB |
Output is correct |
93 |
Correct |
3 ms |
9296 KB |
Output is correct |
94 |
Correct |
2 ms |
9052 KB |
Output is correct |
95 |
Correct |
2 ms |
9052 KB |
Output is correct |
96 |
Correct |
2 ms |
9140 KB |
Output is correct |
97 |
Correct |
2 ms |
9052 KB |
Output is correct |
98 |
Correct |
2 ms |
9260 KB |
Output is correct |
99 |
Correct |
2 ms |
9048 KB |
Output is correct |
100 |
Correct |
2 ms |
9052 KB |
Output is correct |
101 |
Correct |
2 ms |
9052 KB |
Output is correct |
102 |
Correct |
2 ms |
9052 KB |
Output is correct |
103 |
Correct |
2 ms |
9052 KB |
Output is correct |
104 |
Correct |
6 ms |
10072 KB |
Output is correct |
105 |
Correct |
11 ms |
11612 KB |
Output is correct |
106 |
Correct |
2 ms |
9052 KB |
Output is correct |
107 |
Correct |
19 ms |
13628 KB |
Output is correct |
108 |
Correct |
26 ms |
16476 KB |
Output is correct |
109 |
Correct |
2 ms |
9304 KB |
Output is correct |
110 |
Correct |
35 ms |
16672 KB |
Output is correct |
111 |
Correct |
37 ms |
18160 KB |
Output is correct |
112 |
Correct |
2 ms |
9308 KB |
Output is correct |
113 |
Correct |
56 ms |
26356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
11612 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9052 KB |
Output is correct |
2 |
Correct |
2 ms |
9052 KB |
Output is correct |
3 |
Correct |
2 ms |
9048 KB |
Output is correct |
4 |
Correct |
2 ms |
9052 KB |
Output is correct |
5 |
Correct |
2 ms |
9052 KB |
Output is correct |
6 |
Correct |
3 ms |
9052 KB |
Output is correct |
7 |
Correct |
2 ms |
9052 KB |
Output is correct |
8 |
Correct |
2 ms |
9052 KB |
Output is correct |
9 |
Correct |
2 ms |
9052 KB |
Output is correct |
10 |
Correct |
2 ms |
9052 KB |
Output is correct |
11 |
Correct |
2 ms |
9052 KB |
Output is correct |
12 |
Correct |
2 ms |
9052 KB |
Output is correct |
13 |
Correct |
2 ms |
9052 KB |
Output is correct |
14 |
Correct |
2 ms |
9052 KB |
Output is correct |
15 |
Correct |
2 ms |
9144 KB |
Output is correct |
16 |
Correct |
2 ms |
9052 KB |
Output is correct |
17 |
Correct |
2 ms |
9140 KB |
Output is correct |
18 |
Correct |
2 ms |
9052 KB |
Output is correct |
19 |
Correct |
2 ms |
9052 KB |
Output is correct |
20 |
Correct |
2 ms |
9052 KB |
Output is correct |
21 |
Correct |
2 ms |
9052 KB |
Output is correct |
22 |
Correct |
2 ms |
9052 KB |
Output is correct |
23 |
Correct |
2 ms |
9052 KB |
Output is correct |
24 |
Correct |
2 ms |
9052 KB |
Output is correct |
25 |
Correct |
2 ms |
9052 KB |
Output is correct |
26 |
Correct |
2 ms |
9308 KB |
Output is correct |
27 |
Correct |
3 ms |
9308 KB |
Output is correct |
28 |
Correct |
3 ms |
9304 KB |
Output is correct |
29 |
Incorrect |
2 ms |
9308 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
18512 KB |
Output is correct |
2 |
Correct |
41 ms |
18000 KB |
Output is correct |
3 |
Correct |
26 ms |
17496 KB |
Output is correct |
4 |
Correct |
9 ms |
10584 KB |
Output is correct |
5 |
Correct |
7 ms |
9820 KB |
Output is correct |
6 |
Correct |
11 ms |
11100 KB |
Output is correct |
7 |
Correct |
2 ms |
9052 KB |
Output is correct |
8 |
Correct |
19 ms |
13496 KB |
Output is correct |
9 |
Correct |
31 ms |
16536 KB |
Output is correct |
10 |
Correct |
2 ms |
9308 KB |
Output is correct |
11 |
Correct |
42 ms |
16696 KB |
Output is correct |
12 |
Correct |
39 ms |
18260 KB |
Output is correct |
13 |
Correct |
2 ms |
9304 KB |
Output is correct |
14 |
Correct |
2 ms |
9052 KB |
Output is correct |
15 |
Correct |
2 ms |
9052 KB |
Output is correct |
16 |
Correct |
2 ms |
9048 KB |
Output is correct |
17 |
Correct |
2 ms |
9052 KB |
Output is correct |
18 |
Correct |
2 ms |
9052 KB |
Output is correct |
19 |
Correct |
3 ms |
9052 KB |
Output is correct |
20 |
Correct |
2 ms |
9052 KB |
Output is correct |
21 |
Correct |
2 ms |
9052 KB |
Output is correct |
22 |
Correct |
2 ms |
9052 KB |
Output is correct |
23 |
Correct |
2 ms |
9052 KB |
Output is correct |
24 |
Correct |
2 ms |
9052 KB |
Output is correct |
25 |
Correct |
2 ms |
9052 KB |
Output is correct |
26 |
Correct |
2 ms |
9052 KB |
Output is correct |
27 |
Correct |
2 ms |
9052 KB |
Output is correct |
28 |
Correct |
2 ms |
9144 KB |
Output is correct |
29 |
Correct |
2 ms |
9052 KB |
Output is correct |
30 |
Correct |
2 ms |
9140 KB |
Output is correct |
31 |
Correct |
2 ms |
9052 KB |
Output is correct |
32 |
Correct |
2 ms |
9052 KB |
Output is correct |
33 |
Correct |
2 ms |
9052 KB |
Output is correct |
34 |
Correct |
2 ms |
9052 KB |
Output is correct |
35 |
Correct |
2 ms |
9052 KB |
Output is correct |
36 |
Correct |
2 ms |
9052 KB |
Output is correct |
37 |
Correct |
2 ms |
9052 KB |
Output is correct |
38 |
Correct |
2 ms |
9052 KB |
Output is correct |
39 |
Correct |
38 ms |
19792 KB |
Output is correct |
40 |
Correct |
36 ms |
19284 KB |
Output is correct |
41 |
Correct |
27 ms |
18516 KB |
Output is correct |
42 |
Correct |
7 ms |
10844 KB |
Output is correct |
43 |
Correct |
2 ms |
9052 KB |
Output is correct |
44 |
Correct |
2 ms |
9052 KB |
Output is correct |
45 |
Correct |
2 ms |
9052 KB |
Output is correct |
46 |
Correct |
2 ms |
9052 KB |
Output is correct |
47 |
Correct |
2 ms |
9052 KB |
Output is correct |
48 |
Correct |
2 ms |
9052 KB |
Output is correct |
49 |
Correct |
2 ms |
9052 KB |
Output is correct |
50 |
Correct |
2 ms |
9052 KB |
Output is correct |
51 |
Correct |
2 ms |
9052 KB |
Output is correct |
52 |
Correct |
2 ms |
9052 KB |
Output is correct |
53 |
Correct |
2 ms |
9052 KB |
Output is correct |
54 |
Correct |
2 ms |
9052 KB |
Output is correct |
55 |
Correct |
2 ms |
9048 KB |
Output is correct |
56 |
Correct |
2 ms |
9052 KB |
Output is correct |
57 |
Correct |
42 ms |
14528 KB |
Output is correct |
58 |
Correct |
42 ms |
14608 KB |
Output is correct |
59 |
Correct |
45 ms |
14684 KB |
Output is correct |
60 |
Correct |
46 ms |
14904 KB |
Output is correct |
61 |
Correct |
49 ms |
14676 KB |
Output is correct |
62 |
Correct |
44 ms |
14672 KB |
Output is correct |
63 |
Correct |
41 ms |
14416 KB |
Output is correct |
64 |
Correct |
42 ms |
14680 KB |
Output is correct |
65 |
Correct |
43 ms |
14684 KB |
Output is correct |
66 |
Correct |
44 ms |
14684 KB |
Output is correct |
67 |
Correct |
43 ms |
14672 KB |
Output is correct |
68 |
Correct |
46 ms |
14672 KB |
Output is correct |
69 |
Correct |
45 ms |
14932 KB |
Output is correct |
70 |
Correct |
51 ms |
14936 KB |
Output is correct |
71 |
Correct |
2 ms |
9052 KB |
Output is correct |
72 |
Correct |
3 ms |
9308 KB |
Output is correct |
73 |
Correct |
3 ms |
9308 KB |
Output is correct |
74 |
Correct |
3 ms |
9304 KB |
Output is correct |
75 |
Correct |
3 ms |
9304 KB |
Output is correct |
76 |
Correct |
3 ms |
9308 KB |
Output is correct |
77 |
Correct |
3 ms |
9308 KB |
Output is correct |
78 |
Correct |
3 ms |
9304 KB |
Output is correct |
79 |
Correct |
3 ms |
9308 KB |
Output is correct |
80 |
Correct |
50 ms |
14672 KB |
Output is correct |
81 |
Correct |
43 ms |
14684 KB |
Output is correct |
82 |
Correct |
45 ms |
14672 KB |
Output is correct |
83 |
Correct |
49 ms |
15184 KB |
Output is correct |
84 |
Correct |
3 ms |
9308 KB |
Output is correct |
85 |
Correct |
3 ms |
9308 KB |
Output is correct |
86 |
Correct |
3 ms |
9308 KB |
Output is correct |
87 |
Correct |
3 ms |
9308 KB |
Output is correct |
88 |
Correct |
3 ms |
9308 KB |
Output is correct |
89 |
Correct |
3 ms |
9308 KB |
Output is correct |
90 |
Correct |
3 ms |
9272 KB |
Output is correct |
91 |
Correct |
3 ms |
9272 KB |
Output is correct |
92 |
Correct |
3 ms |
9308 KB |
Output is correct |
93 |
Correct |
3 ms |
9296 KB |
Output is correct |
94 |
Correct |
2 ms |
9052 KB |
Output is correct |
95 |
Correct |
2 ms |
9052 KB |
Output is correct |
96 |
Correct |
2 ms |
9140 KB |
Output is correct |
97 |
Correct |
2 ms |
9052 KB |
Output is correct |
98 |
Correct |
2 ms |
9260 KB |
Output is correct |
99 |
Correct |
2 ms |
9048 KB |
Output is correct |
100 |
Correct |
2 ms |
9052 KB |
Output is correct |
101 |
Correct |
2 ms |
9052 KB |
Output is correct |
102 |
Correct |
2 ms |
9052 KB |
Output is correct |
103 |
Correct |
2 ms |
9052 KB |
Output is correct |
104 |
Correct |
6 ms |
10072 KB |
Output is correct |
105 |
Correct |
11 ms |
11612 KB |
Output is correct |
106 |
Correct |
2 ms |
9052 KB |
Output is correct |
107 |
Correct |
19 ms |
13628 KB |
Output is correct |
108 |
Correct |
26 ms |
16476 KB |
Output is correct |
109 |
Correct |
2 ms |
9304 KB |
Output is correct |
110 |
Correct |
35 ms |
16672 KB |
Output is correct |
111 |
Correct |
37 ms |
18160 KB |
Output is correct |
112 |
Correct |
2 ms |
9308 KB |
Output is correct |
113 |
Correct |
56 ms |
26356 KB |
Output is correct |
114 |
Incorrect |
14 ms |
11612 KB |
Output isn't correct |
115 |
Halted |
0 ms |
0 KB |
- |