#include "dreaming.h"
#include <vector>
#include <iostream>
#include <queue>
using namespace std;
#define pii pair<int,int>
#define fst first
#define snd second
#define vpi vector<pii>
#define pub push_back
int n,m,l,dp[100001][2]={},mn = 1e9,rs = 0;
bool bt[100001]={};
priority_queue<int,vector<int>,greater<int>> pq;
vector<vpi> adj;
inline void dfs(int u,int p)
{
bt[u] = 1;
for (auto v:adj[u])
{
if (v.fst!=p)
{
dfs(v.fst,u);
if (dp[v.fst][0] + v.snd > dp[u][0])
{
dp[u][1] = dp[u][0];
dp[u][0] = dp[v.fst][0] + v.snd;
}
else if (dp[v.fst][0] + v.snd > dp[u][1])
{
dp[u][1] = dp[v.fst][0] + v.snd;
}
}
}
}
inline void dfs2(int u,int p,int mx)
{
mn = min(mn,max(mx,dp[u][0]));
rs = max(rs,dp[u][0] + max(dp[u][1],mx));
for (auto v:adj[u])
{
if (v.fst!=p)
{
bt[u] = 1;
dfs2(v.fst,u,max(mx,(dp[u][0]==dp[v.fst][0] + v.snd)?dp[u][1]:dp[u][0]) + v.snd);
}
}
}
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<n;i++) {adj.pub(vpi());}
for (int i=0;i<m;i++)
{
adj[A[i]].pub({B[i],T[i]});
adj[B[i]].pub({A[i],T[i]});
}
for (int i=0;i<n;i++)
{
if (!bt[i])
{
dfs(i,-1);
dfs2(i,-1,0);
//cout<<i<<" "<<mn<<"\n";
pq.push(mn);
mn = 1e9;
}
}
while (pq.size()>1)
{
int v1 = pq.top();pq.pop();
int v2 = pq.top();pq.pop();
pq.push(min(max(v1,v2+l),max(v2,v1+l)));
rs = max(rs,v1+v2+l);
}
return rs;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
10472 KB |
Output is correct |
2 |
Correct |
74 ms |
10340 KB |
Output is correct |
3 |
Correct |
42 ms |
7912 KB |
Output is correct |
4 |
Correct |
11 ms |
1908 KB |
Output is correct |
5 |
Correct |
9 ms |
1268 KB |
Output is correct |
6 |
Correct |
18 ms |
2668 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
31 ms |
4688 KB |
Output is correct |
9 |
Correct |
40 ms |
6508 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
61 ms |
8100 KB |
Output is correct |
12 |
Correct |
66 ms |
9156 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
10472 KB |
Output is correct |
2 |
Correct |
74 ms |
10340 KB |
Output is correct |
3 |
Correct |
42 ms |
7912 KB |
Output is correct |
4 |
Correct |
11 ms |
1908 KB |
Output is correct |
5 |
Correct |
9 ms |
1268 KB |
Output is correct |
6 |
Correct |
18 ms |
2668 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
31 ms |
4688 KB |
Output is correct |
9 |
Correct |
40 ms |
6508 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
61 ms |
8100 KB |
Output is correct |
12 |
Correct |
66 ms |
9156 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
372 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
380 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
2 ms |
376 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
2 ms |
376 KB |
Output is correct |
37 |
Correct |
2 ms |
376 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
10472 KB |
Output is correct |
2 |
Correct |
74 ms |
10340 KB |
Output is correct |
3 |
Correct |
42 ms |
7912 KB |
Output is correct |
4 |
Correct |
11 ms |
1908 KB |
Output is correct |
5 |
Correct |
9 ms |
1268 KB |
Output is correct |
6 |
Correct |
18 ms |
2668 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
31 ms |
4688 KB |
Output is correct |
9 |
Correct |
40 ms |
6508 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
61 ms |
8100 KB |
Output is correct |
12 |
Correct |
66 ms |
9156 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
372 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
380 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
2 ms |
376 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
2 ms |
376 KB |
Output is correct |
37 |
Correct |
2 ms |
376 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
62 ms |
10520 KB |
Output is correct |
40 |
Correct |
62 ms |
10332 KB |
Output is correct |
41 |
Correct |
42 ms |
7912 KB |
Output is correct |
42 |
Correct |
10 ms |
1908 KB |
Output is correct |
43 |
Correct |
2 ms |
376 KB |
Output is correct |
44 |
Correct |
2 ms |
376 KB |
Output is correct |
45 |
Correct |
2 ms |
376 KB |
Output is correct |
46 |
Correct |
2 ms |
380 KB |
Output is correct |
47 |
Correct |
2 ms |
376 KB |
Output is correct |
48 |
Correct |
2 ms |
376 KB |
Output is correct |
49 |
Correct |
2 ms |
376 KB |
Output is correct |
50 |
Correct |
2 ms |
376 KB |
Output is correct |
51 |
Correct |
2 ms |
376 KB |
Output is correct |
52 |
Correct |
2 ms |
376 KB |
Output is correct |
53 |
Correct |
2 ms |
376 KB |
Output is correct |
54 |
Correct |
2 ms |
376 KB |
Output is correct |
55 |
Correct |
2 ms |
376 KB |
Output is correct |
56 |
Correct |
2 ms |
376 KB |
Output is correct |
57 |
Correct |
90 ms |
10084 KB |
Output is correct |
58 |
Correct |
108 ms |
10056 KB |
Output is correct |
59 |
Correct |
99 ms |
9952 KB |
Output is correct |
60 |
Correct |
91 ms |
9952 KB |
Output is correct |
61 |
Correct |
92 ms |
10136 KB |
Output is correct |
62 |
Correct |
96 ms |
10080 KB |
Output is correct |
63 |
Correct |
78 ms |
9800 KB |
Output is correct |
64 |
Correct |
93 ms |
9696 KB |
Output is correct |
65 |
Correct |
84 ms |
10012 KB |
Output is correct |
66 |
Correct |
83 ms |
10084 KB |
Output is correct |
67 |
Correct |
84 ms |
9952 KB |
Output is correct |
68 |
Correct |
90 ms |
9952 KB |
Output is correct |
69 |
Correct |
81 ms |
10208 KB |
Output is correct |
70 |
Correct |
81 ms |
10340 KB |
Output is correct |
71 |
Correct |
3 ms |
376 KB |
Output is correct |
72 |
Correct |
4 ms |
632 KB |
Output is correct |
73 |
Correct |
4 ms |
632 KB |
Output is correct |
74 |
Correct |
4 ms |
632 KB |
Output is correct |
75 |
Correct |
4 ms |
636 KB |
Output is correct |
76 |
Correct |
4 ms |
632 KB |
Output is correct |
77 |
Correct |
4 ms |
632 KB |
Output is correct |
78 |
Correct |
4 ms |
628 KB |
Output is correct |
79 |
Correct |
4 ms |
632 KB |
Output is correct |
80 |
Correct |
83 ms |
9924 KB |
Output is correct |
81 |
Correct |
78 ms |
9952 KB |
Output is correct |
82 |
Correct |
89 ms |
10076 KB |
Output is correct |
83 |
Correct |
99 ms |
10212 KB |
Output is correct |
84 |
Correct |
4 ms |
632 KB |
Output is correct |
85 |
Correct |
3 ms |
504 KB |
Output is correct |
86 |
Correct |
3 ms |
632 KB |
Output is correct |
87 |
Correct |
4 ms |
632 KB |
Output is correct |
88 |
Correct |
4 ms |
632 KB |
Output is correct |
89 |
Correct |
4 ms |
632 KB |
Output is correct |
90 |
Correct |
12 ms |
632 KB |
Output is correct |
91 |
Correct |
4 ms |
632 KB |
Output is correct |
92 |
Correct |
4 ms |
632 KB |
Output is correct |
93 |
Correct |
4 ms |
632 KB |
Output is correct |
94 |
Correct |
2 ms |
380 KB |
Output is correct |
95 |
Correct |
2 ms |
376 KB |
Output is correct |
96 |
Correct |
2 ms |
376 KB |
Output is correct |
97 |
Correct |
2 ms |
376 KB |
Output is correct |
98 |
Correct |
2 ms |
376 KB |
Output is correct |
99 |
Correct |
2 ms |
376 KB |
Output is correct |
100 |
Correct |
2 ms |
376 KB |
Output is correct |
101 |
Correct |
2 ms |
380 KB |
Output is correct |
102 |
Correct |
2 ms |
376 KB |
Output is correct |
103 |
Correct |
2 ms |
368 KB |
Output is correct |
104 |
Correct |
9 ms |
1268 KB |
Output is correct |
105 |
Correct |
17 ms |
2540 KB |
Output is correct |
106 |
Correct |
2 ms |
376 KB |
Output is correct |
107 |
Correct |
33 ms |
4840 KB |
Output is correct |
108 |
Correct |
44 ms |
6376 KB |
Output is correct |
109 |
Correct |
2 ms |
376 KB |
Output is correct |
110 |
Correct |
58 ms |
8036 KB |
Output is correct |
111 |
Correct |
64 ms |
9188 KB |
Output is correct |
112 |
Correct |
2 ms |
376 KB |
Output is correct |
113 |
Correct |
96 ms |
13536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
6628 KB |
Output is correct |
2 |
Incorrect |
46 ms |
6628 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
10472 KB |
Output is correct |
2 |
Correct |
74 ms |
10340 KB |
Output is correct |
3 |
Correct |
42 ms |
7912 KB |
Output is correct |
4 |
Correct |
11 ms |
1908 KB |
Output is correct |
5 |
Correct |
9 ms |
1268 KB |
Output is correct |
6 |
Correct |
18 ms |
2668 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
31 ms |
4688 KB |
Output is correct |
9 |
Correct |
40 ms |
6508 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
61 ms |
8100 KB |
Output is correct |
12 |
Correct |
66 ms |
9156 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
504 KB |
Output is correct |
16 |
Correct |
4 ms |
632 KB |
Output is correct |
17 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
10472 KB |
Output is correct |
2 |
Correct |
74 ms |
10340 KB |
Output is correct |
3 |
Correct |
42 ms |
7912 KB |
Output is correct |
4 |
Correct |
11 ms |
1908 KB |
Output is correct |
5 |
Correct |
9 ms |
1268 KB |
Output is correct |
6 |
Correct |
18 ms |
2668 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
31 ms |
4688 KB |
Output is correct |
9 |
Correct |
40 ms |
6508 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
61 ms |
8100 KB |
Output is correct |
12 |
Correct |
66 ms |
9156 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
372 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
380 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
2 ms |
376 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
2 ms |
376 KB |
Output is correct |
37 |
Correct |
2 ms |
376 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
62 ms |
10520 KB |
Output is correct |
40 |
Correct |
62 ms |
10332 KB |
Output is correct |
41 |
Correct |
42 ms |
7912 KB |
Output is correct |
42 |
Correct |
10 ms |
1908 KB |
Output is correct |
43 |
Correct |
2 ms |
376 KB |
Output is correct |
44 |
Correct |
2 ms |
376 KB |
Output is correct |
45 |
Correct |
2 ms |
376 KB |
Output is correct |
46 |
Correct |
2 ms |
380 KB |
Output is correct |
47 |
Correct |
2 ms |
376 KB |
Output is correct |
48 |
Correct |
2 ms |
376 KB |
Output is correct |
49 |
Correct |
2 ms |
376 KB |
Output is correct |
50 |
Correct |
2 ms |
376 KB |
Output is correct |
51 |
Correct |
2 ms |
376 KB |
Output is correct |
52 |
Correct |
2 ms |
376 KB |
Output is correct |
53 |
Correct |
2 ms |
376 KB |
Output is correct |
54 |
Correct |
2 ms |
376 KB |
Output is correct |
55 |
Correct |
2 ms |
376 KB |
Output is correct |
56 |
Correct |
2 ms |
376 KB |
Output is correct |
57 |
Correct |
90 ms |
10084 KB |
Output is correct |
58 |
Correct |
108 ms |
10056 KB |
Output is correct |
59 |
Correct |
99 ms |
9952 KB |
Output is correct |
60 |
Correct |
91 ms |
9952 KB |
Output is correct |
61 |
Correct |
92 ms |
10136 KB |
Output is correct |
62 |
Correct |
96 ms |
10080 KB |
Output is correct |
63 |
Correct |
78 ms |
9800 KB |
Output is correct |
64 |
Correct |
93 ms |
9696 KB |
Output is correct |
65 |
Correct |
84 ms |
10012 KB |
Output is correct |
66 |
Correct |
83 ms |
10084 KB |
Output is correct |
67 |
Correct |
84 ms |
9952 KB |
Output is correct |
68 |
Correct |
90 ms |
9952 KB |
Output is correct |
69 |
Correct |
81 ms |
10208 KB |
Output is correct |
70 |
Correct |
81 ms |
10340 KB |
Output is correct |
71 |
Correct |
3 ms |
376 KB |
Output is correct |
72 |
Correct |
4 ms |
632 KB |
Output is correct |
73 |
Correct |
4 ms |
632 KB |
Output is correct |
74 |
Correct |
4 ms |
632 KB |
Output is correct |
75 |
Correct |
4 ms |
636 KB |
Output is correct |
76 |
Correct |
4 ms |
632 KB |
Output is correct |
77 |
Correct |
4 ms |
632 KB |
Output is correct |
78 |
Correct |
4 ms |
628 KB |
Output is correct |
79 |
Correct |
4 ms |
632 KB |
Output is correct |
80 |
Correct |
83 ms |
9924 KB |
Output is correct |
81 |
Correct |
78 ms |
9952 KB |
Output is correct |
82 |
Correct |
89 ms |
10076 KB |
Output is correct |
83 |
Correct |
99 ms |
10212 KB |
Output is correct |
84 |
Correct |
4 ms |
632 KB |
Output is correct |
85 |
Correct |
3 ms |
504 KB |
Output is correct |
86 |
Correct |
3 ms |
632 KB |
Output is correct |
87 |
Correct |
4 ms |
632 KB |
Output is correct |
88 |
Correct |
4 ms |
632 KB |
Output is correct |
89 |
Correct |
4 ms |
632 KB |
Output is correct |
90 |
Correct |
12 ms |
632 KB |
Output is correct |
91 |
Correct |
4 ms |
632 KB |
Output is correct |
92 |
Correct |
4 ms |
632 KB |
Output is correct |
93 |
Correct |
4 ms |
632 KB |
Output is correct |
94 |
Correct |
2 ms |
380 KB |
Output is correct |
95 |
Correct |
2 ms |
376 KB |
Output is correct |
96 |
Correct |
2 ms |
376 KB |
Output is correct |
97 |
Correct |
2 ms |
376 KB |
Output is correct |
98 |
Correct |
2 ms |
376 KB |
Output is correct |
99 |
Correct |
2 ms |
376 KB |
Output is correct |
100 |
Correct |
2 ms |
376 KB |
Output is correct |
101 |
Correct |
2 ms |
380 KB |
Output is correct |
102 |
Correct |
2 ms |
376 KB |
Output is correct |
103 |
Correct |
2 ms |
368 KB |
Output is correct |
104 |
Correct |
9 ms |
1268 KB |
Output is correct |
105 |
Correct |
17 ms |
2540 KB |
Output is correct |
106 |
Correct |
2 ms |
376 KB |
Output is correct |
107 |
Correct |
33 ms |
4840 KB |
Output is correct |
108 |
Correct |
44 ms |
6376 KB |
Output is correct |
109 |
Correct |
2 ms |
376 KB |
Output is correct |
110 |
Correct |
58 ms |
8036 KB |
Output is correct |
111 |
Correct |
64 ms |
9188 KB |
Output is correct |
112 |
Correct |
2 ms |
376 KB |
Output is correct |
113 |
Correct |
96 ms |
13536 KB |
Output is correct |
114 |
Correct |
45 ms |
6628 KB |
Output is correct |
115 |
Incorrect |
46 ms |
6628 KB |
Output isn't correct |
116 |
Halted |
0 ms |
0 KB |
- |