//#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
int i,j,s,t;
int a[261523],b[234567],l,r,tt,k,y,z,n,m,x;
const int MAXN=123456;
vector<int>te,so, hursh[212334],an;
struct node {
int endP[2], par, size, val;//*, deed oroi, hemjee, utga
} comp[MAXN];
int wpar[MAXN], depth[MAXN];//deed oroitoigoo holbogdoh urt, gun
vector <int> adj[MAXN];//hurshuud
int root(int u) {
while (comp[u].par >= 0) u = comp[u].par;
return u;//odoogoor hamgiin deed undes
}
bool join(int u, int v, int w) {//u, v, oroinuudiig w utgaar holboh
int x = root(u), y = root(v);//deed undsuudiig ni oloh
if (x == y) {//holbogdson bol
if (comp[x].val < 0) comp[x].val = w;//x ni utga avaagui bol w utgiig olgoh
return false;//
}
if (comp[x].size < comp[y].size) {
swap(x, y); swap(u, v);//ali olon oroitoi olonlogiig i u bolgoh
}
comp[x].size += comp[y].size; comp[y].par = x;//negtgeh, y-iin deed oroig x bolgoh
wpar[y] = w; adj[x].push_back(y);//deed oroitoigoo holbogdoh urt w, xiin hursh y
if (comp[x].val < 0 && comp[y].val < 0 &&
(u == comp[x].endP[0] || u == comp[x].endP[1]) &&
(v == comp[y].endP[0] || v == comp[y].endP[1])) {
if (u == comp[x].endP[0])
comp[x].endP[0] = comp[x].endP[1];
if (v == comp[y].endP[0])
comp[x].endP[1] = comp[y].endP[1];
else comp[x].endP[1] = comp[y].endP[0];
} else if (comp[x].val < 0) comp[x].val = w;
return true;
}
void DFS(int u) {
for (int v : adj[u]) {
depth[v] = depth[u] + 1; DFS(v);//guniig ni dfs ashiglaj oloh
}
}
void init(int N, int M, vector <int> U, vector <int> V, vector <int> W) {
vector <int> sorted(M);
for (i = 0; i <M; i ++)
sorted[i]=i;
sort(sorted.begin(), sorted.end(),[&](int i, int j) {return W[i] < W[j];});
for (int i = 0; i < N; i++) {
comp[i].endP[0] = comp[i].endP[1] = i;
comp[i].par = -1; comp[i].size = 1;
comp[i].val = -1;
}
for (int i : sorted) join(U[i], V[i], W[i]);
for (int i = 0; i < N; i++)
if (comp[i].par < 0) DFS(i);
}
int getMinimumFuelCapacity(int u, int v) {
if (root(u) != root(v)) return -1;
int res = 0;
while (u != v) {
if (depth[u] < depth[v]) swap(u, v);
res = max(res, wpar[u]); u = comp[u].par;
}
while (u >= 0 && comp[u].val < 0) {
res = max(res, wpar[u]); u = comp[u].par;
}
if (u < 0) return -1;
return max(res, comp[u].val);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8140 KB |
Output is correct |
4 |
Correct |
5 ms |
8144 KB |
Output is correct |
5 |
Correct |
5 ms |
8268 KB |
Output is correct |
6 |
Correct |
5 ms |
8268 KB |
Output is correct |
7 |
Correct |
5 ms |
8268 KB |
Output is correct |
8 |
Correct |
5 ms |
8268 KB |
Output is correct |
9 |
Correct |
55 ms |
15108 KB |
Output is correct |
10 |
Correct |
66 ms |
16780 KB |
Output is correct |
11 |
Correct |
63 ms |
16656 KB |
Output is correct |
12 |
Correct |
69 ms |
17040 KB |
Output is correct |
13 |
Correct |
56 ms |
16208 KB |
Output is correct |
14 |
Correct |
60 ms |
15556 KB |
Output is correct |
15 |
Correct |
162 ms |
20184 KB |
Output is correct |
16 |
Correct |
158 ms |
19912 KB |
Output is correct |
17 |
Correct |
161 ms |
20304 KB |
Output is correct |
18 |
Correct |
132 ms |
19576 KB |
Output is correct |
19 |
Correct |
80 ms |
14660 KB |
Output is correct |
20 |
Correct |
159 ms |
21120 KB |
Output is correct |
21 |
Correct |
185 ms |
21268 KB |
Output is correct |
22 |
Correct |
166 ms |
21736 KB |
Output is correct |
23 |
Correct |
129 ms |
20856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
117 ms |
20356 KB |
Output is correct |
4 |
Correct |
124 ms |
20380 KB |
Output is correct |
5 |
Correct |
123 ms |
20552 KB |
Output is correct |
6 |
Correct |
121 ms |
20380 KB |
Output is correct |
7 |
Correct |
125 ms |
20704 KB |
Output is correct |
8 |
Correct |
120 ms |
20300 KB |
Output is correct |
9 |
Correct |
122 ms |
20388 KB |
Output is correct |
10 |
Correct |
120 ms |
20344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8140 KB |
Output is correct |
4 |
Correct |
5 ms |
8144 KB |
Output is correct |
5 |
Correct |
5 ms |
8268 KB |
Output is correct |
6 |
Correct |
5 ms |
8268 KB |
Output is correct |
7 |
Correct |
5 ms |
8268 KB |
Output is correct |
8 |
Correct |
5 ms |
8268 KB |
Output is correct |
9 |
Correct |
5 ms |
8140 KB |
Output is correct |
10 |
Correct |
6 ms |
8268 KB |
Output is correct |
11 |
Correct |
6 ms |
8268 KB |
Output is correct |
12 |
Correct |
5 ms |
8268 KB |
Output is correct |
13 |
Correct |
6 ms |
8268 KB |
Output is correct |
14 |
Correct |
6 ms |
8268 KB |
Output is correct |
15 |
Correct |
6 ms |
8208 KB |
Output is correct |
16 |
Correct |
5 ms |
8268 KB |
Output is correct |
17 |
Correct |
6 ms |
8268 KB |
Output is correct |
18 |
Correct |
5 ms |
8212 KB |
Output is correct |
19 |
Correct |
5 ms |
8268 KB |
Output is correct |
20 |
Correct |
6 ms |
8212 KB |
Output is correct |
21 |
Correct |
6 ms |
8208 KB |
Output is correct |
22 |
Correct |
6 ms |
8208 KB |
Output is correct |
23 |
Correct |
6 ms |
8208 KB |
Output is correct |
24 |
Correct |
6 ms |
8212 KB |
Output is correct |
25 |
Correct |
6 ms |
8212 KB |
Output is correct |
26 |
Correct |
6 ms |
8268 KB |
Output is correct |
27 |
Correct |
5 ms |
8268 KB |
Output is correct |
28 |
Correct |
6 ms |
8252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8140 KB |
Output is correct |
4 |
Correct |
4 ms |
8140 KB |
Output is correct |
5 |
Correct |
5 ms |
8144 KB |
Output is correct |
6 |
Correct |
5 ms |
8268 KB |
Output is correct |
7 |
Correct |
5 ms |
8268 KB |
Output is correct |
8 |
Correct |
5 ms |
8268 KB |
Output is correct |
9 |
Correct |
5 ms |
8268 KB |
Output is correct |
10 |
Correct |
55 ms |
15108 KB |
Output is correct |
11 |
Correct |
66 ms |
16780 KB |
Output is correct |
12 |
Correct |
63 ms |
16656 KB |
Output is correct |
13 |
Correct |
69 ms |
17040 KB |
Output is correct |
14 |
Correct |
56 ms |
16208 KB |
Output is correct |
15 |
Correct |
6 ms |
8268 KB |
Output is correct |
16 |
Correct |
6 ms |
8268 KB |
Output is correct |
17 |
Correct |
5 ms |
8268 KB |
Output is correct |
18 |
Correct |
6 ms |
8268 KB |
Output is correct |
19 |
Correct |
6 ms |
8268 KB |
Output is correct |
20 |
Correct |
6 ms |
8208 KB |
Output is correct |
21 |
Correct |
5 ms |
8268 KB |
Output is correct |
22 |
Correct |
6 ms |
8268 KB |
Output is correct |
23 |
Correct |
5 ms |
8212 KB |
Output is correct |
24 |
Correct |
5 ms |
8268 KB |
Output is correct |
25 |
Correct |
6 ms |
8212 KB |
Output is correct |
26 |
Correct |
6 ms |
8208 KB |
Output is correct |
27 |
Correct |
6 ms |
8208 KB |
Output is correct |
28 |
Correct |
6 ms |
8208 KB |
Output is correct |
29 |
Correct |
6 ms |
8212 KB |
Output is correct |
30 |
Correct |
6 ms |
8212 KB |
Output is correct |
31 |
Correct |
6 ms |
8268 KB |
Output is correct |
32 |
Correct |
5 ms |
8268 KB |
Output is correct |
33 |
Correct |
6 ms |
8252 KB |
Output is correct |
34 |
Correct |
13 ms |
9388 KB |
Output is correct |
35 |
Correct |
70 ms |
16784 KB |
Output is correct |
36 |
Correct |
70 ms |
16780 KB |
Output is correct |
37 |
Correct |
71 ms |
16836 KB |
Output is correct |
38 |
Correct |
68 ms |
16636 KB |
Output is correct |
39 |
Correct |
76 ms |
16504 KB |
Output is correct |
40 |
Correct |
61 ms |
15764 KB |
Output is correct |
41 |
Correct |
74 ms |
17036 KB |
Output is correct |
42 |
Correct |
73 ms |
16776 KB |
Output is correct |
43 |
Correct |
54 ms |
15932 KB |
Output is correct |
44 |
Correct |
73 ms |
16972 KB |
Output is correct |
45 |
Correct |
96 ms |
18268 KB |
Output is correct |
46 |
Correct |
72 ms |
16784 KB |
Output is correct |
47 |
Correct |
76 ms |
16836 KB |
Output is correct |
48 |
Correct |
77 ms |
17040 KB |
Output is correct |
49 |
Correct |
81 ms |
15296 KB |
Output is correct |
50 |
Correct |
63 ms |
14020 KB |
Output is correct |
51 |
Correct |
82 ms |
16852 KB |
Output is correct |
52 |
Correct |
114 ms |
20036 KB |
Output is correct |
53 |
Correct |
121 ms |
20656 KB |
Output is correct |
54 |
Correct |
132 ms |
21408 KB |
Output is correct |
55 |
Correct |
55 ms |
16140 KB |
Output is correct |
56 |
Correct |
116 ms |
20288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8140 KB |
Output is correct |
4 |
Correct |
5 ms |
8144 KB |
Output is correct |
5 |
Correct |
5 ms |
8268 KB |
Output is correct |
6 |
Correct |
5 ms |
8268 KB |
Output is correct |
7 |
Correct |
5 ms |
8268 KB |
Output is correct |
8 |
Correct |
5 ms |
8268 KB |
Output is correct |
9 |
Correct |
55 ms |
15108 KB |
Output is correct |
10 |
Correct |
66 ms |
16780 KB |
Output is correct |
11 |
Correct |
63 ms |
16656 KB |
Output is correct |
12 |
Correct |
69 ms |
17040 KB |
Output is correct |
13 |
Correct |
56 ms |
16208 KB |
Output is correct |
14 |
Correct |
60 ms |
15556 KB |
Output is correct |
15 |
Correct |
162 ms |
20184 KB |
Output is correct |
16 |
Correct |
158 ms |
19912 KB |
Output is correct |
17 |
Correct |
161 ms |
20304 KB |
Output is correct |
18 |
Correct |
132 ms |
19576 KB |
Output is correct |
19 |
Correct |
117 ms |
20356 KB |
Output is correct |
20 |
Correct |
124 ms |
20380 KB |
Output is correct |
21 |
Correct |
123 ms |
20552 KB |
Output is correct |
22 |
Correct |
121 ms |
20380 KB |
Output is correct |
23 |
Correct |
125 ms |
20704 KB |
Output is correct |
24 |
Correct |
120 ms |
20300 KB |
Output is correct |
25 |
Correct |
122 ms |
20388 KB |
Output is correct |
26 |
Correct |
120 ms |
20344 KB |
Output is correct |
27 |
Correct |
6 ms |
8268 KB |
Output is correct |
28 |
Correct |
6 ms |
8268 KB |
Output is correct |
29 |
Correct |
5 ms |
8268 KB |
Output is correct |
30 |
Correct |
6 ms |
8268 KB |
Output is correct |
31 |
Correct |
6 ms |
8268 KB |
Output is correct |
32 |
Correct |
6 ms |
8208 KB |
Output is correct |
33 |
Correct |
5 ms |
8268 KB |
Output is correct |
34 |
Correct |
6 ms |
8268 KB |
Output is correct |
35 |
Correct |
5 ms |
8212 KB |
Output is correct |
36 |
Correct |
13 ms |
9388 KB |
Output is correct |
37 |
Correct |
70 ms |
16784 KB |
Output is correct |
38 |
Correct |
70 ms |
16780 KB |
Output is correct |
39 |
Correct |
71 ms |
16836 KB |
Output is correct |
40 |
Correct |
68 ms |
16636 KB |
Output is correct |
41 |
Correct |
76 ms |
16504 KB |
Output is correct |
42 |
Correct |
61 ms |
15764 KB |
Output is correct |
43 |
Correct |
74 ms |
17036 KB |
Output is correct |
44 |
Correct |
73 ms |
16776 KB |
Output is correct |
45 |
Correct |
54 ms |
15932 KB |
Output is correct |
46 |
Correct |
73 ms |
16972 KB |
Output is correct |
47 |
Correct |
20 ms |
9824 KB |
Output is correct |
48 |
Correct |
166 ms |
20756 KB |
Output is correct |
49 |
Correct |
182 ms |
20768 KB |
Output is correct |
50 |
Correct |
160 ms |
20712 KB |
Output is correct |
51 |
Correct |
165 ms |
20684 KB |
Output is correct |
52 |
Correct |
154 ms |
20368 KB |
Output is correct |
53 |
Correct |
133 ms |
19404 KB |
Output is correct |
54 |
Correct |
173 ms |
21344 KB |
Output is correct |
55 |
Correct |
167 ms |
20768 KB |
Output is correct |
56 |
Correct |
127 ms |
19944 KB |
Output is correct |
57 |
Correct |
162 ms |
21208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8140 KB |
Output is correct |
4 |
Correct |
4 ms |
8140 KB |
Output is correct |
5 |
Correct |
5 ms |
8144 KB |
Output is correct |
6 |
Correct |
5 ms |
8268 KB |
Output is correct |
7 |
Correct |
5 ms |
8268 KB |
Output is correct |
8 |
Correct |
5 ms |
8268 KB |
Output is correct |
9 |
Correct |
5 ms |
8268 KB |
Output is correct |
10 |
Correct |
55 ms |
15108 KB |
Output is correct |
11 |
Correct |
66 ms |
16780 KB |
Output is correct |
12 |
Correct |
63 ms |
16656 KB |
Output is correct |
13 |
Correct |
69 ms |
17040 KB |
Output is correct |
14 |
Correct |
56 ms |
16208 KB |
Output is correct |
15 |
Correct |
60 ms |
15556 KB |
Output is correct |
16 |
Correct |
162 ms |
20184 KB |
Output is correct |
17 |
Correct |
158 ms |
19912 KB |
Output is correct |
18 |
Correct |
161 ms |
20304 KB |
Output is correct |
19 |
Correct |
132 ms |
19576 KB |
Output is correct |
20 |
Correct |
117 ms |
20356 KB |
Output is correct |
21 |
Correct |
124 ms |
20380 KB |
Output is correct |
22 |
Correct |
123 ms |
20552 KB |
Output is correct |
23 |
Correct |
121 ms |
20380 KB |
Output is correct |
24 |
Correct |
125 ms |
20704 KB |
Output is correct |
25 |
Correct |
120 ms |
20300 KB |
Output is correct |
26 |
Correct |
122 ms |
20388 KB |
Output is correct |
27 |
Correct |
120 ms |
20344 KB |
Output is correct |
28 |
Correct |
6 ms |
8268 KB |
Output is correct |
29 |
Correct |
6 ms |
8268 KB |
Output is correct |
30 |
Correct |
5 ms |
8268 KB |
Output is correct |
31 |
Correct |
6 ms |
8268 KB |
Output is correct |
32 |
Correct |
6 ms |
8268 KB |
Output is correct |
33 |
Correct |
6 ms |
8208 KB |
Output is correct |
34 |
Correct |
5 ms |
8268 KB |
Output is correct |
35 |
Correct |
6 ms |
8268 KB |
Output is correct |
36 |
Correct |
5 ms |
8212 KB |
Output is correct |
37 |
Correct |
13 ms |
9388 KB |
Output is correct |
38 |
Correct |
70 ms |
16784 KB |
Output is correct |
39 |
Correct |
70 ms |
16780 KB |
Output is correct |
40 |
Correct |
71 ms |
16836 KB |
Output is correct |
41 |
Correct |
68 ms |
16636 KB |
Output is correct |
42 |
Correct |
76 ms |
16504 KB |
Output is correct |
43 |
Correct |
61 ms |
15764 KB |
Output is correct |
44 |
Correct |
74 ms |
17036 KB |
Output is correct |
45 |
Correct |
73 ms |
16776 KB |
Output is correct |
46 |
Correct |
54 ms |
15932 KB |
Output is correct |
47 |
Correct |
73 ms |
16972 KB |
Output is correct |
48 |
Correct |
20 ms |
9824 KB |
Output is correct |
49 |
Correct |
166 ms |
20756 KB |
Output is correct |
50 |
Correct |
182 ms |
20768 KB |
Output is correct |
51 |
Correct |
160 ms |
20712 KB |
Output is correct |
52 |
Correct |
165 ms |
20684 KB |
Output is correct |
53 |
Correct |
154 ms |
20368 KB |
Output is correct |
54 |
Correct |
133 ms |
19404 KB |
Output is correct |
55 |
Correct |
173 ms |
21344 KB |
Output is correct |
56 |
Correct |
167 ms |
20768 KB |
Output is correct |
57 |
Correct |
127 ms |
19944 KB |
Output is correct |
58 |
Correct |
162 ms |
21208 KB |
Output is correct |
59 |
Correct |
80 ms |
14660 KB |
Output is correct |
60 |
Correct |
159 ms |
21120 KB |
Output is correct |
61 |
Correct |
185 ms |
21268 KB |
Output is correct |
62 |
Correct |
166 ms |
21736 KB |
Output is correct |
63 |
Correct |
129 ms |
20856 KB |
Output is correct |
64 |
Correct |
5 ms |
8268 KB |
Output is correct |
65 |
Correct |
6 ms |
8212 KB |
Output is correct |
66 |
Correct |
6 ms |
8208 KB |
Output is correct |
67 |
Correct |
6 ms |
8208 KB |
Output is correct |
68 |
Correct |
6 ms |
8208 KB |
Output is correct |
69 |
Correct |
6 ms |
8212 KB |
Output is correct |
70 |
Correct |
6 ms |
8212 KB |
Output is correct |
71 |
Correct |
6 ms |
8268 KB |
Output is correct |
72 |
Correct |
5 ms |
8268 KB |
Output is correct |
73 |
Correct |
6 ms |
8252 KB |
Output is correct |
74 |
Correct |
96 ms |
18268 KB |
Output is correct |
75 |
Correct |
72 ms |
16784 KB |
Output is correct |
76 |
Correct |
76 ms |
16836 KB |
Output is correct |
77 |
Correct |
77 ms |
17040 KB |
Output is correct |
78 |
Correct |
81 ms |
15296 KB |
Output is correct |
79 |
Correct |
63 ms |
14020 KB |
Output is correct |
80 |
Correct |
82 ms |
16852 KB |
Output is correct |
81 |
Correct |
114 ms |
20036 KB |
Output is correct |
82 |
Correct |
121 ms |
20656 KB |
Output is correct |
83 |
Correct |
132 ms |
21408 KB |
Output is correct |
84 |
Correct |
55 ms |
16140 KB |
Output is correct |
85 |
Correct |
116 ms |
20288 KB |
Output is correct |
86 |
Correct |
53 ms |
12740 KB |
Output is correct |
87 |
Correct |
169 ms |
20796 KB |
Output is correct |
88 |
Correct |
167 ms |
20716 KB |
Output is correct |
89 |
Correct |
146 ms |
20312 KB |
Output is correct |
90 |
Correct |
156 ms |
17992 KB |
Output is correct |
91 |
Correct |
153 ms |
18072 KB |
Output is correct |
92 |
Correct |
171 ms |
20028 KB |
Output is correct |
93 |
Correct |
203 ms |
22152 KB |
Output is correct |
94 |
Correct |
208 ms |
22436 KB |
Output is correct |
95 |
Correct |
231 ms |
22992 KB |
Output is correct |
96 |
Correct |
130 ms |
20196 KB |
Output is correct |
97 |
Correct |
175 ms |
21700 KB |
Output is correct |