#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
vector <pair <int, int>> ke[100001];
int dp[100001],dp2[100001],ch[100001],mx;
priority_queue <int, vector <int>, greater <int>> q;
void dfs(int u, int p){
ch[u]=1;
for (auto [v,w]:ke[u])
if (v!=p){
dfs(v,u);
dp[u]=max(dp[u],dp[v]+w);
}
}
void dfs2(int u, int p){
ch[u]=0;
int mx=0,idx=-1,mx2=0;
for (auto [v,w]:ke[u]){
if (v==p)
continue;
if (dp[v]+w>mx){
mx2=mx;
mx=dp[v]+w;
idx=v;
}
else
mx2=max(mx2,dp[v]+w);
}
for (auto [v,w]:ke[u]){
if (v==p)
continue;
dp2[v]=max(dp2[u],(v==idx?mx2:mx))+w;
dfs2(v,u);
}
}
int dfs3(int u, int p){
ch[u]=1;
int mn=dp[u];
for (auto [v,w]:ke[u])
if (v!=p)
mn=min(mn,dfs3(v,u));
return mn;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for (int i=0;i<M;i++){
ke[A[i]].emplace_back(B[i],T[i]);
ke[B[i]].emplace_back(A[i],T[i]);
}
for (int i=0;i<N;i++)
if (!ch[i])
dfs(i,i);
for (int i=0;i<N;i++)
if (ch[i])
dfs2(i,i);
for (int i=0;i<N;i++){
dp[i]=max(dp[i],dp2[i]);
mx=max(mx,dp[i]);
}
for (int i=0;i<N;i++)
if (!ch[i])
q.push(dfs3(i,i));
while (q.size()>1){
int x=q.top();
q.pop();
int y=q.top();
q.pop();
mx=max(mx,x+y+L);
q.push(min(max(x,y+L),max(x+L,y)));
}
return mx;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
12624 KB |
Output is correct |
2 |
Correct |
38 ms |
12288 KB |
Output is correct |
3 |
Correct |
27 ms |
11600 KB |
Output is correct |
4 |
Correct |
5 ms |
5980 KB |
Output is correct |
5 |
Correct |
6 ms |
5720 KB |
Output is correct |
6 |
Correct |
9 ms |
6488 KB |
Output is correct |
7 |
Correct |
2 ms |
4952 KB |
Output is correct |
8 |
Correct |
17 ms |
8024 KB |
Output is correct |
9 |
Correct |
21 ms |
10328 KB |
Output is correct |
10 |
Correct |
1 ms |
4952 KB |
Output is correct |
11 |
Correct |
31 ms |
10328 KB |
Output is correct |
12 |
Correct |
35 ms |
11344 KB |
Output is correct |
13 |
Correct |
1 ms |
4952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4952 KB |
Output is correct |
3 |
Correct |
1 ms |
4952 KB |
Output is correct |
4 |
Correct |
1 ms |
4952 KB |
Output is correct |
5 |
Correct |
1 ms |
4952 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4952 KB |
Output is correct |
8 |
Correct |
1 ms |
4952 KB |
Output is correct |
9 |
Correct |
1 ms |
4952 KB |
Output is correct |
10 |
Correct |
1 ms |
4952 KB |
Output is correct |
11 |
Correct |
1 ms |
4956 KB |
Output is correct |
12 |
Correct |
1 ms |
4952 KB |
Output is correct |
13 |
Correct |
1 ms |
4952 KB |
Output is correct |
14 |
Correct |
1 ms |
4952 KB |
Output is correct |
15 |
Correct |
1 ms |
4952 KB |
Output is correct |
16 |
Correct |
4 ms |
4952 KB |
Output is correct |
17 |
Correct |
1 ms |
4952 KB |
Output is correct |
18 |
Correct |
1 ms |
4952 KB |
Output is correct |
19 |
Correct |
1 ms |
4952 KB |
Output is correct |
20 |
Correct |
1 ms |
4952 KB |
Output is correct |
21 |
Correct |
1 ms |
4952 KB |
Output is correct |
22 |
Correct |
1 ms |
4952 KB |
Output is correct |
23 |
Correct |
1 ms |
4952 KB |
Output is correct |
24 |
Correct |
1 ms |
4952 KB |
Output is correct |
25 |
Correct |
1 ms |
4952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
12624 KB |
Output is correct |
2 |
Correct |
38 ms |
12288 KB |
Output is correct |
3 |
Correct |
27 ms |
11600 KB |
Output is correct |
4 |
Correct |
5 ms |
5980 KB |
Output is correct |
5 |
Correct |
6 ms |
5720 KB |
Output is correct |
6 |
Correct |
9 ms |
6488 KB |
Output is correct |
7 |
Correct |
2 ms |
4952 KB |
Output is correct |
8 |
Correct |
17 ms |
8024 KB |
Output is correct |
9 |
Correct |
21 ms |
10328 KB |
Output is correct |
10 |
Correct |
1 ms |
4952 KB |
Output is correct |
11 |
Correct |
31 ms |
10328 KB |
Output is correct |
12 |
Correct |
35 ms |
11344 KB |
Output is correct |
13 |
Correct |
1 ms |
4952 KB |
Output is correct |
14 |
Correct |
1 ms |
4952 KB |
Output is correct |
15 |
Correct |
1 ms |
4952 KB |
Output is correct |
16 |
Correct |
1 ms |
4952 KB |
Output is correct |
17 |
Correct |
1 ms |
4952 KB |
Output is correct |
18 |
Correct |
1 ms |
4952 KB |
Output is correct |
19 |
Correct |
1 ms |
4956 KB |
Output is correct |
20 |
Correct |
1 ms |
4952 KB |
Output is correct |
21 |
Correct |
1 ms |
4952 KB |
Output is correct |
22 |
Correct |
1 ms |
4952 KB |
Output is correct |
23 |
Correct |
1 ms |
4952 KB |
Output is correct |
24 |
Correct |
1 ms |
4956 KB |
Output is correct |
25 |
Correct |
1 ms |
4952 KB |
Output is correct |
26 |
Correct |
1 ms |
4952 KB |
Output is correct |
27 |
Correct |
1 ms |
4952 KB |
Output is correct |
28 |
Correct |
1 ms |
4952 KB |
Output is correct |
29 |
Correct |
4 ms |
4952 KB |
Output is correct |
30 |
Correct |
1 ms |
4952 KB |
Output is correct |
31 |
Correct |
1 ms |
4952 KB |
Output is correct |
32 |
Correct |
1 ms |
4952 KB |
Output is correct |
33 |
Correct |
1 ms |
4952 KB |
Output is correct |
34 |
Correct |
1 ms |
4952 KB |
Output is correct |
35 |
Correct |
1 ms |
4952 KB |
Output is correct |
36 |
Correct |
1 ms |
4952 KB |
Output is correct |
37 |
Correct |
1 ms |
4952 KB |
Output is correct |
38 |
Correct |
1 ms |
4952 KB |
Output is correct |
39 |
Correct |
34 ms |
13904 KB |
Output is correct |
40 |
Correct |
34 ms |
13504 KB |
Output is correct |
41 |
Correct |
23 ms |
12632 KB |
Output is correct |
42 |
Correct |
5 ms |
6232 KB |
Output is correct |
43 |
Correct |
1 ms |
4952 KB |
Output is correct |
44 |
Correct |
2 ms |
4956 KB |
Output is correct |
45 |
Correct |
1 ms |
4952 KB |
Output is correct |
46 |
Correct |
1 ms |
4952 KB |
Output is correct |
47 |
Correct |
1 ms |
4956 KB |
Output is correct |
48 |
Correct |
1 ms |
4952 KB |
Output is correct |
49 |
Correct |
1 ms |
4952 KB |
Output is correct |
50 |
Correct |
2 ms |
4956 KB |
Output is correct |
51 |
Correct |
1 ms |
4952 KB |
Output is correct |
52 |
Correct |
1 ms |
4952 KB |
Output is correct |
53 |
Correct |
1 ms |
5208 KB |
Output is correct |
54 |
Correct |
1 ms |
4952 KB |
Output is correct |
55 |
Correct |
1 ms |
5156 KB |
Output is correct |
56 |
Correct |
2 ms |
4952 KB |
Output is correct |
57 |
Correct |
44 ms |
10320 KB |
Output is correct |
58 |
Correct |
43 ms |
10452 KB |
Output is correct |
59 |
Correct |
55 ms |
10576 KB |
Output is correct |
60 |
Correct |
40 ms |
10312 KB |
Output is correct |
61 |
Correct |
39 ms |
10320 KB |
Output is correct |
62 |
Correct |
41 ms |
10480 KB |
Output is correct |
63 |
Correct |
52 ms |
10084 KB |
Output is correct |
64 |
Correct |
38 ms |
10064 KB |
Output is correct |
65 |
Correct |
39 ms |
10320 KB |
Output is correct |
66 |
Correct |
40 ms |
10328 KB |
Output is correct |
67 |
Correct |
57 ms |
10576 KB |
Output is correct |
68 |
Correct |
50 ms |
10320 KB |
Output is correct |
69 |
Correct |
42 ms |
10576 KB |
Output is correct |
70 |
Correct |
42 ms |
10576 KB |
Output is correct |
71 |
Correct |
1 ms |
4952 KB |
Output is correct |
72 |
Correct |
2 ms |
4952 KB |
Output is correct |
73 |
Correct |
2 ms |
5036 KB |
Output is correct |
74 |
Correct |
2 ms |
4956 KB |
Output is correct |
75 |
Correct |
2 ms |
4952 KB |
Output is correct |
76 |
Correct |
2 ms |
4956 KB |
Output is correct |
77 |
Correct |
2 ms |
4952 KB |
Output is correct |
78 |
Correct |
2 ms |
4952 KB |
Output is correct |
79 |
Correct |
2 ms |
4952 KB |
Output is correct |
80 |
Correct |
42 ms |
10320 KB |
Output is correct |
81 |
Correct |
53 ms |
10320 KB |
Output is correct |
82 |
Correct |
38 ms |
10328 KB |
Output is correct |
83 |
Correct |
44 ms |
10348 KB |
Output is correct |
84 |
Correct |
2 ms |
4952 KB |
Output is correct |
85 |
Correct |
2 ms |
4952 KB |
Output is correct |
86 |
Correct |
2 ms |
4952 KB |
Output is correct |
87 |
Correct |
2 ms |
4952 KB |
Output is correct |
88 |
Correct |
2 ms |
4952 KB |
Output is correct |
89 |
Correct |
2 ms |
4960 KB |
Output is correct |
90 |
Correct |
3 ms |
4952 KB |
Output is correct |
91 |
Correct |
2 ms |
4952 KB |
Output is correct |
92 |
Correct |
2 ms |
4952 KB |
Output is correct |
93 |
Correct |
2 ms |
4952 KB |
Output is correct |
94 |
Correct |
1 ms |
4952 KB |
Output is correct |
95 |
Correct |
1 ms |
4952 KB |
Output is correct |
96 |
Correct |
1 ms |
4952 KB |
Output is correct |
97 |
Correct |
1 ms |
4952 KB |
Output is correct |
98 |
Correct |
1 ms |
4952 KB |
Output is correct |
99 |
Correct |
1 ms |
4952 KB |
Output is correct |
100 |
Correct |
1 ms |
4952 KB |
Output is correct |
101 |
Correct |
1 ms |
4952 KB |
Output is correct |
102 |
Correct |
1 ms |
4952 KB |
Output is correct |
103 |
Correct |
1 ms |
4952 KB |
Output is correct |
104 |
Correct |
5 ms |
5464 KB |
Output is correct |
105 |
Correct |
9 ms |
7000 KB |
Output is correct |
106 |
Correct |
1 ms |
4952 KB |
Output is correct |
107 |
Correct |
16 ms |
8536 KB |
Output is correct |
108 |
Correct |
26 ms |
10832 KB |
Output is correct |
109 |
Correct |
1 ms |
4952 KB |
Output is correct |
110 |
Correct |
32 ms |
11344 KB |
Output is correct |
111 |
Correct |
38 ms |
12628 KB |
Output is correct |
112 |
Correct |
1 ms |
4952 KB |
Output is correct |
113 |
Correct |
53 ms |
19024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
7388 KB |
Output is correct |
2 |
Incorrect |
22 ms |
7384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4952 KB |
Output is correct |
3 |
Correct |
1 ms |
4952 KB |
Output is correct |
4 |
Correct |
1 ms |
4952 KB |
Output is correct |
5 |
Correct |
1 ms |
4952 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4952 KB |
Output is correct |
8 |
Correct |
1 ms |
4952 KB |
Output is correct |
9 |
Correct |
1 ms |
4952 KB |
Output is correct |
10 |
Correct |
1 ms |
4952 KB |
Output is correct |
11 |
Correct |
1 ms |
4956 KB |
Output is correct |
12 |
Correct |
1 ms |
4952 KB |
Output is correct |
13 |
Correct |
1 ms |
4952 KB |
Output is correct |
14 |
Correct |
1 ms |
4952 KB |
Output is correct |
15 |
Correct |
1 ms |
4952 KB |
Output is correct |
16 |
Correct |
4 ms |
4952 KB |
Output is correct |
17 |
Correct |
1 ms |
4952 KB |
Output is correct |
18 |
Correct |
1 ms |
4952 KB |
Output is correct |
19 |
Correct |
1 ms |
4952 KB |
Output is correct |
20 |
Correct |
1 ms |
4952 KB |
Output is correct |
21 |
Correct |
1 ms |
4952 KB |
Output is correct |
22 |
Correct |
1 ms |
4952 KB |
Output is correct |
23 |
Correct |
1 ms |
4952 KB |
Output is correct |
24 |
Correct |
1 ms |
4952 KB |
Output is correct |
25 |
Correct |
1 ms |
4952 KB |
Output is correct |
26 |
Correct |
1 ms |
4952 KB |
Output is correct |
27 |
Correct |
2 ms |
5208 KB |
Output is correct |
28 |
Correct |
2 ms |
4952 KB |
Output is correct |
29 |
Incorrect |
1 ms |
4956 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
12624 KB |
Output is correct |
2 |
Correct |
38 ms |
12288 KB |
Output is correct |
3 |
Correct |
27 ms |
11600 KB |
Output is correct |
4 |
Correct |
5 ms |
5980 KB |
Output is correct |
5 |
Correct |
6 ms |
5720 KB |
Output is correct |
6 |
Correct |
9 ms |
6488 KB |
Output is correct |
7 |
Correct |
2 ms |
4952 KB |
Output is correct |
8 |
Correct |
17 ms |
8024 KB |
Output is correct |
9 |
Correct |
21 ms |
10328 KB |
Output is correct |
10 |
Correct |
1 ms |
4952 KB |
Output is correct |
11 |
Correct |
31 ms |
10328 KB |
Output is correct |
12 |
Correct |
35 ms |
11344 KB |
Output is correct |
13 |
Correct |
1 ms |
4952 KB |
Output is correct |
14 |
Correct |
1 ms |
4952 KB |
Output is correct |
15 |
Correct |
1 ms |
4952 KB |
Output is correct |
16 |
Correct |
1 ms |
4952 KB |
Output is correct |
17 |
Correct |
1 ms |
4952 KB |
Output is correct |
18 |
Correct |
1 ms |
4952 KB |
Output is correct |
19 |
Correct |
1 ms |
4956 KB |
Output is correct |
20 |
Correct |
1 ms |
4952 KB |
Output is correct |
21 |
Correct |
1 ms |
4952 KB |
Output is correct |
22 |
Correct |
1 ms |
4952 KB |
Output is correct |
23 |
Correct |
1 ms |
4952 KB |
Output is correct |
24 |
Correct |
1 ms |
4956 KB |
Output is correct |
25 |
Correct |
1 ms |
4952 KB |
Output is correct |
26 |
Correct |
1 ms |
4952 KB |
Output is correct |
27 |
Correct |
1 ms |
4952 KB |
Output is correct |
28 |
Correct |
1 ms |
4952 KB |
Output is correct |
29 |
Correct |
4 ms |
4952 KB |
Output is correct |
30 |
Correct |
1 ms |
4952 KB |
Output is correct |
31 |
Correct |
1 ms |
4952 KB |
Output is correct |
32 |
Correct |
1 ms |
4952 KB |
Output is correct |
33 |
Correct |
1 ms |
4952 KB |
Output is correct |
34 |
Correct |
1 ms |
4952 KB |
Output is correct |
35 |
Correct |
1 ms |
4952 KB |
Output is correct |
36 |
Correct |
1 ms |
4952 KB |
Output is correct |
37 |
Correct |
1 ms |
4952 KB |
Output is correct |
38 |
Correct |
1 ms |
4952 KB |
Output is correct |
39 |
Correct |
34 ms |
13904 KB |
Output is correct |
40 |
Correct |
34 ms |
13504 KB |
Output is correct |
41 |
Correct |
23 ms |
12632 KB |
Output is correct |
42 |
Correct |
5 ms |
6232 KB |
Output is correct |
43 |
Correct |
1 ms |
4952 KB |
Output is correct |
44 |
Correct |
2 ms |
4956 KB |
Output is correct |
45 |
Correct |
1 ms |
4952 KB |
Output is correct |
46 |
Correct |
1 ms |
4952 KB |
Output is correct |
47 |
Correct |
1 ms |
4956 KB |
Output is correct |
48 |
Correct |
1 ms |
4952 KB |
Output is correct |
49 |
Correct |
1 ms |
4952 KB |
Output is correct |
50 |
Correct |
2 ms |
4956 KB |
Output is correct |
51 |
Correct |
1 ms |
4952 KB |
Output is correct |
52 |
Correct |
1 ms |
4952 KB |
Output is correct |
53 |
Correct |
1 ms |
5208 KB |
Output is correct |
54 |
Correct |
1 ms |
4952 KB |
Output is correct |
55 |
Correct |
1 ms |
5156 KB |
Output is correct |
56 |
Correct |
2 ms |
4952 KB |
Output is correct |
57 |
Correct |
44 ms |
10320 KB |
Output is correct |
58 |
Correct |
43 ms |
10452 KB |
Output is correct |
59 |
Correct |
55 ms |
10576 KB |
Output is correct |
60 |
Correct |
40 ms |
10312 KB |
Output is correct |
61 |
Correct |
39 ms |
10320 KB |
Output is correct |
62 |
Correct |
41 ms |
10480 KB |
Output is correct |
63 |
Correct |
52 ms |
10084 KB |
Output is correct |
64 |
Correct |
38 ms |
10064 KB |
Output is correct |
65 |
Correct |
39 ms |
10320 KB |
Output is correct |
66 |
Correct |
40 ms |
10328 KB |
Output is correct |
67 |
Correct |
57 ms |
10576 KB |
Output is correct |
68 |
Correct |
50 ms |
10320 KB |
Output is correct |
69 |
Correct |
42 ms |
10576 KB |
Output is correct |
70 |
Correct |
42 ms |
10576 KB |
Output is correct |
71 |
Correct |
1 ms |
4952 KB |
Output is correct |
72 |
Correct |
2 ms |
4952 KB |
Output is correct |
73 |
Correct |
2 ms |
5036 KB |
Output is correct |
74 |
Correct |
2 ms |
4956 KB |
Output is correct |
75 |
Correct |
2 ms |
4952 KB |
Output is correct |
76 |
Correct |
2 ms |
4956 KB |
Output is correct |
77 |
Correct |
2 ms |
4952 KB |
Output is correct |
78 |
Correct |
2 ms |
4952 KB |
Output is correct |
79 |
Correct |
2 ms |
4952 KB |
Output is correct |
80 |
Correct |
42 ms |
10320 KB |
Output is correct |
81 |
Correct |
53 ms |
10320 KB |
Output is correct |
82 |
Correct |
38 ms |
10328 KB |
Output is correct |
83 |
Correct |
44 ms |
10348 KB |
Output is correct |
84 |
Correct |
2 ms |
4952 KB |
Output is correct |
85 |
Correct |
2 ms |
4952 KB |
Output is correct |
86 |
Correct |
2 ms |
4952 KB |
Output is correct |
87 |
Correct |
2 ms |
4952 KB |
Output is correct |
88 |
Correct |
2 ms |
4952 KB |
Output is correct |
89 |
Correct |
2 ms |
4960 KB |
Output is correct |
90 |
Correct |
3 ms |
4952 KB |
Output is correct |
91 |
Correct |
2 ms |
4952 KB |
Output is correct |
92 |
Correct |
2 ms |
4952 KB |
Output is correct |
93 |
Correct |
2 ms |
4952 KB |
Output is correct |
94 |
Correct |
1 ms |
4952 KB |
Output is correct |
95 |
Correct |
1 ms |
4952 KB |
Output is correct |
96 |
Correct |
1 ms |
4952 KB |
Output is correct |
97 |
Correct |
1 ms |
4952 KB |
Output is correct |
98 |
Correct |
1 ms |
4952 KB |
Output is correct |
99 |
Correct |
1 ms |
4952 KB |
Output is correct |
100 |
Correct |
1 ms |
4952 KB |
Output is correct |
101 |
Correct |
1 ms |
4952 KB |
Output is correct |
102 |
Correct |
1 ms |
4952 KB |
Output is correct |
103 |
Correct |
1 ms |
4952 KB |
Output is correct |
104 |
Correct |
5 ms |
5464 KB |
Output is correct |
105 |
Correct |
9 ms |
7000 KB |
Output is correct |
106 |
Correct |
1 ms |
4952 KB |
Output is correct |
107 |
Correct |
16 ms |
8536 KB |
Output is correct |
108 |
Correct |
26 ms |
10832 KB |
Output is correct |
109 |
Correct |
1 ms |
4952 KB |
Output is correct |
110 |
Correct |
32 ms |
11344 KB |
Output is correct |
111 |
Correct |
38 ms |
12628 KB |
Output is correct |
112 |
Correct |
1 ms |
4952 KB |
Output is correct |
113 |
Correct |
53 ms |
19024 KB |
Output is correct |
114 |
Correct |
24 ms |
7388 KB |
Output is correct |
115 |
Incorrect |
22 ms |
7384 KB |
Output isn't correct |
116 |
Halted |
0 ms |
0 KB |
- |