#include <bits/stdc++.h>
#include "dreaming.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ii = pair<ll, ll>;
using vi = vector<int>;
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define lb lower_bound
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
const int oo = 1e18 + 7;
int res, par[100001], E[100001], D[100001];
vector<ii> adj[100001];
vector<int> S;
bool vis[100001];
int findSet(int v) {
if(par[v] == v) return v;
return par[v] = findSet(par[v]);
}
void unionSet(int u, int v, int L) {
u = findSet(u); v = findSet(v);
if(u == v) return;
if(max(E[u], E[v] + L) > max(E[v], E[u] + L)) swap(u, v);
res = max(res, E[u] + E[v] + L);
E[u] = max(E[u], E[v] + L);
par[v] = u;
}
void dfs(int v, int p, int dep) {
D[v] = dep; S.pb(v);
for(auto u : adj[v]) {
if(u.ff == p) continue;
dfs(u.ff, v, dep + u.ss);
}
}
void dfs(int v, int p, int dep, vector<int>& d) {
d[v] = dep;
for(auto u : adj[v]) {
if(u.ff == p) continue;
dfs(u.ff, v, dep + u.ss, d);
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for(int l = 0; l < N; l++) par[l] = l;
for(int l = 0; l < M; l++) {
int U = A[l], V = B[l], W = T[l];
adj[U].pb({V, W}), adj[V].pb({U, W});
}
for(int l = 0; l < N; l++) {
if(vis[l]) continue;
dfs(l, l, 0);
int p = l;
for(auto u : S) {
if(D[u] <= D[p]) continue;
p = u;
}
vector<int> D1(N + 1, 0);
dfs(p, p, 0, D1); int to = p;
for(auto u : S) {
if(D1[u] <= D1[to]) continue;
to = u; res = max(res, D1[u]);
}
vector<int> D2(N + 1, 0); dfs(to, to, 0, D2);
int med = p, curr = 1e9 + 7;
for(auto u : S) {
if(D1[u] + D2[u] == D1[to]) {
if(max(D1[u], D2[u]) < curr)
med = u, curr = max(D1[u], D2[u]);
}
}
for(auto u : S) par[u] = med, vis[u] = 1;
E[med] = curr; S.clear();
}
for(int l = 1; l < N; l++)
unionSet(l - 1, l, L);
return res;
}
Compilation message
dreaming.cpp:21:29: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
21 | const int oo = 1e18 + 7;
| ~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
13264 KB |
Output is correct |
2 |
Correct |
45 ms |
13040 KB |
Output is correct |
3 |
Correct |
32 ms |
10896 KB |
Output is correct |
4 |
Correct |
7 ms |
4180 KB |
Output is correct |
5 |
Correct |
9 ms |
3796 KB |
Output is correct |
6 |
Correct |
12 ms |
5152 KB |
Output is correct |
7 |
Correct |
2 ms |
2712 KB |
Output is correct |
8 |
Correct |
22 ms |
7504 KB |
Output is correct |
9 |
Correct |
29 ms |
9532 KB |
Output is correct |
10 |
Correct |
2 ms |
2772 KB |
Output is correct |
11 |
Correct |
52 ms |
10824 KB |
Output is correct |
12 |
Correct |
55 ms |
12176 KB |
Output is correct |
13 |
Correct |
2 ms |
2900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2624 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2672 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
2 ms |
2644 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
1 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2644 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
2 ms |
2664 KB |
Output is correct |
24 |
Correct |
2 ms |
2644 KB |
Output is correct |
25 |
Correct |
3 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
13264 KB |
Output is correct |
2 |
Correct |
45 ms |
13040 KB |
Output is correct |
3 |
Correct |
32 ms |
10896 KB |
Output is correct |
4 |
Correct |
7 ms |
4180 KB |
Output is correct |
5 |
Correct |
9 ms |
3796 KB |
Output is correct |
6 |
Correct |
12 ms |
5152 KB |
Output is correct |
7 |
Correct |
2 ms |
2712 KB |
Output is correct |
8 |
Correct |
22 ms |
7504 KB |
Output is correct |
9 |
Correct |
29 ms |
9532 KB |
Output is correct |
10 |
Correct |
2 ms |
2772 KB |
Output is correct |
11 |
Correct |
52 ms |
10824 KB |
Output is correct |
12 |
Correct |
55 ms |
12176 KB |
Output is correct |
13 |
Correct |
2 ms |
2900 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2624 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
2 ms |
2644 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2672 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2644 KB |
Output is correct |
22 |
Correct |
1 ms |
2644 KB |
Output is correct |
23 |
Correct |
2 ms |
2644 KB |
Output is correct |
24 |
Correct |
2 ms |
2644 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
2 ms |
2644 KB |
Output is correct |
27 |
Correct |
1 ms |
2644 KB |
Output is correct |
28 |
Correct |
1 ms |
2644 KB |
Output is correct |
29 |
Correct |
2 ms |
2644 KB |
Output is correct |
30 |
Correct |
2 ms |
2644 KB |
Output is correct |
31 |
Correct |
2 ms |
2644 KB |
Output is correct |
32 |
Correct |
2 ms |
2644 KB |
Output is correct |
33 |
Correct |
1 ms |
2644 KB |
Output is correct |
34 |
Correct |
2 ms |
2644 KB |
Output is correct |
35 |
Correct |
2 ms |
2644 KB |
Output is correct |
36 |
Correct |
2 ms |
2664 KB |
Output is correct |
37 |
Correct |
2 ms |
2644 KB |
Output is correct |
38 |
Correct |
3 ms |
2688 KB |
Output is correct |
39 |
Correct |
46 ms |
13332 KB |
Output is correct |
40 |
Correct |
44 ms |
12996 KB |
Output is correct |
41 |
Correct |
29 ms |
10800 KB |
Output is correct |
42 |
Correct |
8 ms |
4220 KB |
Output is correct |
43 |
Correct |
1 ms |
2668 KB |
Output is correct |
44 |
Correct |
2 ms |
2644 KB |
Output is correct |
45 |
Correct |
2 ms |
2644 KB |
Output is correct |
46 |
Correct |
2 ms |
2660 KB |
Output is correct |
47 |
Correct |
2 ms |
2644 KB |
Output is correct |
48 |
Correct |
2 ms |
2644 KB |
Output is correct |
49 |
Correct |
2 ms |
2644 KB |
Output is correct |
50 |
Correct |
2 ms |
2644 KB |
Output is correct |
51 |
Correct |
2 ms |
2644 KB |
Output is correct |
52 |
Correct |
1 ms |
2644 KB |
Output is correct |
53 |
Correct |
1 ms |
2664 KB |
Output is correct |
54 |
Correct |
2 ms |
2668 KB |
Output is correct |
55 |
Correct |
2 ms |
2644 KB |
Output is correct |
56 |
Correct |
2 ms |
2644 KB |
Output is correct |
57 |
Correct |
72 ms |
11948 KB |
Output is correct |
58 |
Correct |
67 ms |
11796 KB |
Output is correct |
59 |
Correct |
70 ms |
11648 KB |
Output is correct |
60 |
Correct |
67 ms |
11520 KB |
Output is correct |
61 |
Correct |
66 ms |
11552 KB |
Output is correct |
62 |
Correct |
62 ms |
11340 KB |
Output is correct |
63 |
Correct |
56 ms |
11236 KB |
Output is correct |
64 |
Correct |
58 ms |
11204 KB |
Output is correct |
65 |
Correct |
63 ms |
11260 KB |
Output is correct |
66 |
Correct |
64 ms |
11364 KB |
Output is correct |
67 |
Correct |
72 ms |
11632 KB |
Output is correct |
68 |
Correct |
70 ms |
11716 KB |
Output is correct |
69 |
Correct |
71 ms |
11460 KB |
Output is correct |
70 |
Correct |
69 ms |
11548 KB |
Output is correct |
71 |
Correct |
2 ms |
2644 KB |
Output is correct |
72 |
Correct |
3 ms |
2900 KB |
Output is correct |
73 |
Correct |
3 ms |
2900 KB |
Output is correct |
74 |
Correct |
5 ms |
2900 KB |
Output is correct |
75 |
Correct |
3 ms |
2900 KB |
Output is correct |
76 |
Correct |
3 ms |
2900 KB |
Output is correct |
77 |
Correct |
3 ms |
2900 KB |
Output is correct |
78 |
Correct |
3 ms |
2900 KB |
Output is correct |
79 |
Correct |
3 ms |
2900 KB |
Output is correct |
80 |
Correct |
70 ms |
11468 KB |
Output is correct |
81 |
Correct |
69 ms |
11608 KB |
Output is correct |
82 |
Correct |
68 ms |
11516 KB |
Output is correct |
83 |
Correct |
87 ms |
11484 KB |
Output is correct |
84 |
Correct |
3 ms |
2816 KB |
Output is correct |
85 |
Correct |
2 ms |
2772 KB |
Output is correct |
86 |
Correct |
3 ms |
2900 KB |
Output is correct |
87 |
Correct |
3 ms |
2900 KB |
Output is correct |
88 |
Correct |
2 ms |
2900 KB |
Output is correct |
89 |
Correct |
3 ms |
2820 KB |
Output is correct |
90 |
Correct |
3 ms |
2900 KB |
Output is correct |
91 |
Correct |
3 ms |
2900 KB |
Output is correct |
92 |
Correct |
3 ms |
2900 KB |
Output is correct |
93 |
Correct |
3 ms |
2844 KB |
Output is correct |
94 |
Correct |
2 ms |
2672 KB |
Output is correct |
95 |
Correct |
1 ms |
2644 KB |
Output is correct |
96 |
Correct |
2 ms |
2664 KB |
Output is correct |
97 |
Correct |
1 ms |
2668 KB |
Output is correct |
98 |
Correct |
2 ms |
2644 KB |
Output is correct |
99 |
Correct |
2 ms |
2644 KB |
Output is correct |
100 |
Correct |
1 ms |
2644 KB |
Output is correct |
101 |
Correct |
2 ms |
2644 KB |
Output is correct |
102 |
Correct |
2 ms |
2644 KB |
Output is correct |
103 |
Correct |
2 ms |
2644 KB |
Output is correct |
104 |
Correct |
7 ms |
3796 KB |
Output is correct |
105 |
Correct |
12 ms |
5176 KB |
Output is correct |
106 |
Correct |
2 ms |
2644 KB |
Output is correct |
107 |
Correct |
35 ms |
7496 KB |
Output is correct |
108 |
Correct |
30 ms |
9536 KB |
Output is correct |
109 |
Correct |
2 ms |
2672 KB |
Output is correct |
110 |
Correct |
45 ms |
10844 KB |
Output is correct |
111 |
Correct |
55 ms |
12212 KB |
Output is correct |
112 |
Correct |
2 ms |
2772 KB |
Output is correct |
113 |
Correct |
81 ms |
17472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1092 ms |
6728 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2624 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2672 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
2 ms |
2644 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
1 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2644 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
2 ms |
2664 KB |
Output is correct |
24 |
Correct |
2 ms |
2644 KB |
Output is correct |
25 |
Correct |
3 ms |
2688 KB |
Output is correct |
26 |
Correct |
3 ms |
2644 KB |
Output is correct |
27 |
Correct |
2 ms |
2772 KB |
Output is correct |
28 |
Correct |
3 ms |
2900 KB |
Output is correct |
29 |
Correct |
2 ms |
2664 KB |
Output is correct |
30 |
Correct |
2 ms |
2772 KB |
Output is correct |
31 |
Correct |
3 ms |
2900 KB |
Output is correct |
32 |
Correct |
2 ms |
2644 KB |
Output is correct |
33 |
Incorrect |
2 ms |
2772 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
13264 KB |
Output is correct |
2 |
Correct |
45 ms |
13040 KB |
Output is correct |
3 |
Correct |
32 ms |
10896 KB |
Output is correct |
4 |
Correct |
7 ms |
4180 KB |
Output is correct |
5 |
Correct |
9 ms |
3796 KB |
Output is correct |
6 |
Correct |
12 ms |
5152 KB |
Output is correct |
7 |
Correct |
2 ms |
2712 KB |
Output is correct |
8 |
Correct |
22 ms |
7504 KB |
Output is correct |
9 |
Correct |
29 ms |
9532 KB |
Output is correct |
10 |
Correct |
2 ms |
2772 KB |
Output is correct |
11 |
Correct |
52 ms |
10824 KB |
Output is correct |
12 |
Correct |
55 ms |
12176 KB |
Output is correct |
13 |
Correct |
2 ms |
2900 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2624 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
2 ms |
2644 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2672 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2644 KB |
Output is correct |
22 |
Correct |
1 ms |
2644 KB |
Output is correct |
23 |
Correct |
2 ms |
2644 KB |
Output is correct |
24 |
Correct |
2 ms |
2644 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
2 ms |
2644 KB |
Output is correct |
27 |
Correct |
1 ms |
2644 KB |
Output is correct |
28 |
Correct |
1 ms |
2644 KB |
Output is correct |
29 |
Correct |
2 ms |
2644 KB |
Output is correct |
30 |
Correct |
2 ms |
2644 KB |
Output is correct |
31 |
Correct |
2 ms |
2644 KB |
Output is correct |
32 |
Correct |
2 ms |
2644 KB |
Output is correct |
33 |
Correct |
1 ms |
2644 KB |
Output is correct |
34 |
Correct |
2 ms |
2644 KB |
Output is correct |
35 |
Correct |
2 ms |
2644 KB |
Output is correct |
36 |
Correct |
2 ms |
2664 KB |
Output is correct |
37 |
Correct |
2 ms |
2644 KB |
Output is correct |
38 |
Correct |
3 ms |
2688 KB |
Output is correct |
39 |
Correct |
46 ms |
13332 KB |
Output is correct |
40 |
Correct |
44 ms |
12996 KB |
Output is correct |
41 |
Correct |
29 ms |
10800 KB |
Output is correct |
42 |
Correct |
8 ms |
4220 KB |
Output is correct |
43 |
Correct |
1 ms |
2668 KB |
Output is correct |
44 |
Correct |
2 ms |
2644 KB |
Output is correct |
45 |
Correct |
2 ms |
2644 KB |
Output is correct |
46 |
Correct |
2 ms |
2660 KB |
Output is correct |
47 |
Correct |
2 ms |
2644 KB |
Output is correct |
48 |
Correct |
2 ms |
2644 KB |
Output is correct |
49 |
Correct |
2 ms |
2644 KB |
Output is correct |
50 |
Correct |
2 ms |
2644 KB |
Output is correct |
51 |
Correct |
2 ms |
2644 KB |
Output is correct |
52 |
Correct |
1 ms |
2644 KB |
Output is correct |
53 |
Correct |
1 ms |
2664 KB |
Output is correct |
54 |
Correct |
2 ms |
2668 KB |
Output is correct |
55 |
Correct |
2 ms |
2644 KB |
Output is correct |
56 |
Correct |
2 ms |
2644 KB |
Output is correct |
57 |
Correct |
72 ms |
11948 KB |
Output is correct |
58 |
Correct |
67 ms |
11796 KB |
Output is correct |
59 |
Correct |
70 ms |
11648 KB |
Output is correct |
60 |
Correct |
67 ms |
11520 KB |
Output is correct |
61 |
Correct |
66 ms |
11552 KB |
Output is correct |
62 |
Correct |
62 ms |
11340 KB |
Output is correct |
63 |
Correct |
56 ms |
11236 KB |
Output is correct |
64 |
Correct |
58 ms |
11204 KB |
Output is correct |
65 |
Correct |
63 ms |
11260 KB |
Output is correct |
66 |
Correct |
64 ms |
11364 KB |
Output is correct |
67 |
Correct |
72 ms |
11632 KB |
Output is correct |
68 |
Correct |
70 ms |
11716 KB |
Output is correct |
69 |
Correct |
71 ms |
11460 KB |
Output is correct |
70 |
Correct |
69 ms |
11548 KB |
Output is correct |
71 |
Correct |
2 ms |
2644 KB |
Output is correct |
72 |
Correct |
3 ms |
2900 KB |
Output is correct |
73 |
Correct |
3 ms |
2900 KB |
Output is correct |
74 |
Correct |
5 ms |
2900 KB |
Output is correct |
75 |
Correct |
3 ms |
2900 KB |
Output is correct |
76 |
Correct |
3 ms |
2900 KB |
Output is correct |
77 |
Correct |
3 ms |
2900 KB |
Output is correct |
78 |
Correct |
3 ms |
2900 KB |
Output is correct |
79 |
Correct |
3 ms |
2900 KB |
Output is correct |
80 |
Correct |
70 ms |
11468 KB |
Output is correct |
81 |
Correct |
69 ms |
11608 KB |
Output is correct |
82 |
Correct |
68 ms |
11516 KB |
Output is correct |
83 |
Correct |
87 ms |
11484 KB |
Output is correct |
84 |
Correct |
3 ms |
2816 KB |
Output is correct |
85 |
Correct |
2 ms |
2772 KB |
Output is correct |
86 |
Correct |
3 ms |
2900 KB |
Output is correct |
87 |
Correct |
3 ms |
2900 KB |
Output is correct |
88 |
Correct |
2 ms |
2900 KB |
Output is correct |
89 |
Correct |
3 ms |
2820 KB |
Output is correct |
90 |
Correct |
3 ms |
2900 KB |
Output is correct |
91 |
Correct |
3 ms |
2900 KB |
Output is correct |
92 |
Correct |
3 ms |
2900 KB |
Output is correct |
93 |
Correct |
3 ms |
2844 KB |
Output is correct |
94 |
Correct |
2 ms |
2672 KB |
Output is correct |
95 |
Correct |
1 ms |
2644 KB |
Output is correct |
96 |
Correct |
2 ms |
2664 KB |
Output is correct |
97 |
Correct |
1 ms |
2668 KB |
Output is correct |
98 |
Correct |
2 ms |
2644 KB |
Output is correct |
99 |
Correct |
2 ms |
2644 KB |
Output is correct |
100 |
Correct |
1 ms |
2644 KB |
Output is correct |
101 |
Correct |
2 ms |
2644 KB |
Output is correct |
102 |
Correct |
2 ms |
2644 KB |
Output is correct |
103 |
Correct |
2 ms |
2644 KB |
Output is correct |
104 |
Correct |
7 ms |
3796 KB |
Output is correct |
105 |
Correct |
12 ms |
5176 KB |
Output is correct |
106 |
Correct |
2 ms |
2644 KB |
Output is correct |
107 |
Correct |
35 ms |
7496 KB |
Output is correct |
108 |
Correct |
30 ms |
9536 KB |
Output is correct |
109 |
Correct |
2 ms |
2672 KB |
Output is correct |
110 |
Correct |
45 ms |
10844 KB |
Output is correct |
111 |
Correct |
55 ms |
12212 KB |
Output is correct |
112 |
Correct |
2 ms |
2772 KB |
Output is correct |
113 |
Correct |
81 ms |
17472 KB |
Output is correct |
114 |
Execution timed out |
1092 ms |
6728 KB |
Time limit exceeded |
115 |
Halted |
0 ms |
0 KB |
- |