#include "swap.h"
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 2e5+10;
const int lgmx = 18;
const int inf = 1e9+69;
struct edge
{
int x, y, z;
inline bool operator<(const edge& o) const
{
return z < o.z;
}
} edgs[maxn];
int N, M;
vector<int> comp[maxn];
int root[maxn];
bool ispath[maxn];
int fnp[maxn];
pii sars[maxn];
int epar[maxn];
int dpar[maxn];
vector<int> kids[maxn];
inline void invldp(int r, int z)
{
if(!ispath[r]) return;
for(int u: comp[r])
{
ispath[u] = false;
fnp[u] = z;
}
}
inline bool isin(int x, pii p)
{
return x == p.first or x == p.second;
}
inline void mrg(int x, int y, int z)
{
if(comp[root[x]].size() < comp[root[y]].size())
swap(x, y);
int rx = root[x];
int ry = root[y];
if(rx == ry)
{
invldp(rx, z);
}
else
{
if( ispath[rx] and ispath[ry] and isin(x, sars[rx]) and isin(y, sars[ry]) )
{
int a = sars[rx].first^sars[rx].second ^ x;
int b = sars[ry].first^sars[ry].second ^ y;
sars[rx] = pii(a, b);
}
else
{
invldp(rx, z);
invldp(ry, z);
}
epar[ry] = z;
dpar[ry] = rx;
for(int u: comp[ry])
{
root[u] = rx;
comp[rx].push_back(u);
}
comp[ry].clear();
}
}
int tin[maxn];
int tout[maxn];
int timer = 0;
void dfs(int v)
{
tin[v] = timer++;
for(int u: kids[v])
dfs(u);
tout[v] = timer;
}
inline bool isanc(int x, int y)
{
return (tin[x] <= tin[y] and tout[y] <= tout[x]);
}
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W)
{
::N = N;
::M = M;
for(int i = 0; i < N; i++)
{
root[i] = i;
comp[i].push_back(i);
ispath[i] = true;
fnp[i] = inf;
sars[i] = pii(i, i);
dpar[i] = i;
}
for(int i = 0; i < M; i++)
edgs[i] = {V[i], U[i], W[i]};
sort(edgs, edgs+M);
for(int i = 0; i < M; i++)
{
int x = edgs[i].x;
int y = edgs[i].y;
int z = edgs[i].z;
mrg(x, y, z);
}
int r = 0;
for(int i = 0; i < N; i++)
{
if(dpar[i] != i)
kids[dpar[i]].push_back(i);
else
r = i;
}
dfs(r);
}
int getMinimumFuelCapacity(int x, int y)
{
int ans = max(fnp[x], fnp[y]);
int v = x;
while(!isanc(v, y))
{
ans = max(ans, epar[v]);
v = dpar[v];
}
v = y;
while(!isanc(v, x))
{
ans = max(ans, epar[v]);
v = dpar[v];
}
if(ans == inf)
return -1;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9696 KB |
Output is correct |
2 |
Correct |
7 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9684 KB |
Output is correct |
5 |
Correct |
6 ms |
9812 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
6 ms |
9812 KB |
Output is correct |
8 |
Correct |
5 ms |
9812 KB |
Output is correct |
9 |
Correct |
65 ms |
20592 KB |
Output is correct |
10 |
Correct |
77 ms |
22988 KB |
Output is correct |
11 |
Correct |
76 ms |
22716 KB |
Output is correct |
12 |
Correct |
95 ms |
23536 KB |
Output is correct |
13 |
Correct |
64 ms |
20832 KB |
Output is correct |
14 |
Correct |
69 ms |
20576 KB |
Output is correct |
15 |
Correct |
143 ms |
24908 KB |
Output is correct |
16 |
Correct |
141 ms |
24560 KB |
Output is correct |
17 |
Correct |
198 ms |
25388 KB |
Output is correct |
18 |
Correct |
116 ms |
22792 KB |
Output is correct |
19 |
Correct |
66 ms |
15308 KB |
Output is correct |
20 |
Correct |
147 ms |
26080 KB |
Output is correct |
21 |
Correct |
162 ms |
25808 KB |
Output is correct |
22 |
Correct |
159 ms |
26716 KB |
Output is correct |
23 |
Correct |
120 ms |
24276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9696 KB |
Output is correct |
2 |
Correct |
7 ms |
9684 KB |
Output is correct |
3 |
Correct |
113 ms |
22896 KB |
Output is correct |
4 |
Correct |
120 ms |
23352 KB |
Output is correct |
5 |
Correct |
110 ms |
23264 KB |
Output is correct |
6 |
Correct |
106 ms |
23260 KB |
Output is correct |
7 |
Correct |
137 ms |
23508 KB |
Output is correct |
8 |
Correct |
113 ms |
22900 KB |
Output is correct |
9 |
Correct |
111 ms |
23180 KB |
Output is correct |
10 |
Correct |
145 ms |
22872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9696 KB |
Output is correct |
2 |
Correct |
7 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9684 KB |
Output is correct |
5 |
Correct |
6 ms |
9812 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
6 ms |
9812 KB |
Output is correct |
8 |
Correct |
5 ms |
9812 KB |
Output is correct |
9 |
Correct |
5 ms |
9684 KB |
Output is correct |
10 |
Correct |
5 ms |
9812 KB |
Output is correct |
11 |
Correct |
6 ms |
9812 KB |
Output is correct |
12 |
Correct |
5 ms |
9812 KB |
Output is correct |
13 |
Correct |
5 ms |
9812 KB |
Output is correct |
14 |
Correct |
6 ms |
9812 KB |
Output is correct |
15 |
Correct |
6 ms |
9812 KB |
Output is correct |
16 |
Correct |
7 ms |
9812 KB |
Output is correct |
17 |
Correct |
5 ms |
9812 KB |
Output is correct |
18 |
Correct |
5 ms |
9812 KB |
Output is correct |
19 |
Correct |
5 ms |
9812 KB |
Output is correct |
20 |
Correct |
6 ms |
9832 KB |
Output is correct |
21 |
Correct |
5 ms |
9812 KB |
Output is correct |
22 |
Correct |
5 ms |
9812 KB |
Output is correct |
23 |
Correct |
7 ms |
9760 KB |
Output is correct |
24 |
Correct |
6 ms |
9812 KB |
Output is correct |
25 |
Correct |
6 ms |
9812 KB |
Output is correct |
26 |
Correct |
7 ms |
9812 KB |
Output is correct |
27 |
Correct |
5 ms |
9812 KB |
Output is correct |
28 |
Correct |
8 ms |
9812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9696 KB |
Output is correct |
3 |
Correct |
7 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9684 KB |
Output is correct |
5 |
Correct |
6 ms |
9684 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
6 ms |
9812 KB |
Output is correct |
8 |
Correct |
6 ms |
9812 KB |
Output is correct |
9 |
Correct |
5 ms |
9812 KB |
Output is correct |
10 |
Correct |
65 ms |
20592 KB |
Output is correct |
11 |
Correct |
77 ms |
22988 KB |
Output is correct |
12 |
Correct |
76 ms |
22716 KB |
Output is correct |
13 |
Correct |
95 ms |
23536 KB |
Output is correct |
14 |
Correct |
64 ms |
20832 KB |
Output is correct |
15 |
Correct |
5 ms |
9812 KB |
Output is correct |
16 |
Correct |
6 ms |
9812 KB |
Output is correct |
17 |
Correct |
5 ms |
9812 KB |
Output is correct |
18 |
Correct |
5 ms |
9812 KB |
Output is correct |
19 |
Correct |
6 ms |
9812 KB |
Output is correct |
20 |
Correct |
6 ms |
9812 KB |
Output is correct |
21 |
Correct |
7 ms |
9812 KB |
Output is correct |
22 |
Correct |
5 ms |
9812 KB |
Output is correct |
23 |
Correct |
5 ms |
9812 KB |
Output is correct |
24 |
Correct |
5 ms |
9812 KB |
Output is correct |
25 |
Correct |
6 ms |
9832 KB |
Output is correct |
26 |
Correct |
5 ms |
9812 KB |
Output is correct |
27 |
Correct |
5 ms |
9812 KB |
Output is correct |
28 |
Correct |
7 ms |
9760 KB |
Output is correct |
29 |
Correct |
6 ms |
9812 KB |
Output is correct |
30 |
Correct |
6 ms |
9812 KB |
Output is correct |
31 |
Correct |
7 ms |
9812 KB |
Output is correct |
32 |
Correct |
5 ms |
9812 KB |
Output is correct |
33 |
Correct |
8 ms |
9812 KB |
Output is correct |
34 |
Correct |
13 ms |
11348 KB |
Output is correct |
35 |
Correct |
82 ms |
23544 KB |
Output is correct |
36 |
Correct |
85 ms |
23440 KB |
Output is correct |
37 |
Correct |
82 ms |
23208 KB |
Output is correct |
38 |
Correct |
89 ms |
22800 KB |
Output is correct |
39 |
Correct |
87 ms |
22624 KB |
Output is correct |
40 |
Correct |
93 ms |
21520 KB |
Output is correct |
41 |
Correct |
86 ms |
23548 KB |
Output is correct |
42 |
Correct |
95 ms |
23572 KB |
Output is correct |
43 |
Correct |
67 ms |
20936 KB |
Output is correct |
44 |
Correct |
80 ms |
22528 KB |
Output is correct |
45 |
Correct |
85 ms |
21348 KB |
Output is correct |
46 |
Correct |
95 ms |
23440 KB |
Output is correct |
47 |
Correct |
93 ms |
22340 KB |
Output is correct |
48 |
Correct |
82 ms |
21604 KB |
Output is correct |
49 |
Correct |
59 ms |
15404 KB |
Output is correct |
50 |
Correct |
50 ms |
14580 KB |
Output is correct |
51 |
Correct |
72 ms |
19412 KB |
Output is correct |
52 |
Correct |
121 ms |
25300 KB |
Output is correct |
53 |
Correct |
109 ms |
24468 KB |
Output is correct |
54 |
Correct |
128 ms |
27036 KB |
Output is correct |
55 |
Correct |
71 ms |
20980 KB |
Output is correct |
56 |
Correct |
102 ms |
23972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9696 KB |
Output is correct |
2 |
Correct |
7 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9684 KB |
Output is correct |
5 |
Correct |
6 ms |
9812 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
6 ms |
9812 KB |
Output is correct |
8 |
Correct |
5 ms |
9812 KB |
Output is correct |
9 |
Correct |
65 ms |
20592 KB |
Output is correct |
10 |
Correct |
77 ms |
22988 KB |
Output is correct |
11 |
Correct |
76 ms |
22716 KB |
Output is correct |
12 |
Correct |
95 ms |
23536 KB |
Output is correct |
13 |
Correct |
64 ms |
20832 KB |
Output is correct |
14 |
Correct |
69 ms |
20576 KB |
Output is correct |
15 |
Correct |
143 ms |
24908 KB |
Output is correct |
16 |
Correct |
141 ms |
24560 KB |
Output is correct |
17 |
Correct |
198 ms |
25388 KB |
Output is correct |
18 |
Correct |
116 ms |
22792 KB |
Output is correct |
19 |
Correct |
113 ms |
22896 KB |
Output is correct |
20 |
Correct |
120 ms |
23352 KB |
Output is correct |
21 |
Correct |
110 ms |
23264 KB |
Output is correct |
22 |
Correct |
106 ms |
23260 KB |
Output is correct |
23 |
Correct |
137 ms |
23508 KB |
Output is correct |
24 |
Correct |
113 ms |
22900 KB |
Output is correct |
25 |
Correct |
111 ms |
23180 KB |
Output is correct |
26 |
Correct |
145 ms |
22872 KB |
Output is correct |
27 |
Correct |
5 ms |
9812 KB |
Output is correct |
28 |
Correct |
6 ms |
9812 KB |
Output is correct |
29 |
Correct |
5 ms |
9812 KB |
Output is correct |
30 |
Correct |
5 ms |
9812 KB |
Output is correct |
31 |
Correct |
6 ms |
9812 KB |
Output is correct |
32 |
Correct |
6 ms |
9812 KB |
Output is correct |
33 |
Correct |
7 ms |
9812 KB |
Output is correct |
34 |
Correct |
5 ms |
9812 KB |
Output is correct |
35 |
Correct |
5 ms |
9812 KB |
Output is correct |
36 |
Correct |
13 ms |
11348 KB |
Output is correct |
37 |
Correct |
82 ms |
23544 KB |
Output is correct |
38 |
Correct |
85 ms |
23440 KB |
Output is correct |
39 |
Correct |
82 ms |
23208 KB |
Output is correct |
40 |
Correct |
89 ms |
22800 KB |
Output is correct |
41 |
Correct |
87 ms |
22624 KB |
Output is correct |
42 |
Correct |
93 ms |
21520 KB |
Output is correct |
43 |
Correct |
86 ms |
23548 KB |
Output is correct |
44 |
Correct |
95 ms |
23572 KB |
Output is correct |
45 |
Correct |
67 ms |
20936 KB |
Output is correct |
46 |
Correct |
80 ms |
22528 KB |
Output is correct |
47 |
Correct |
18 ms |
11604 KB |
Output is correct |
48 |
Correct |
173 ms |
25976 KB |
Output is correct |
49 |
Correct |
158 ms |
25816 KB |
Output is correct |
50 |
Correct |
144 ms |
25832 KB |
Output is correct |
51 |
Correct |
190 ms |
25528 KB |
Output is correct |
52 |
Correct |
140 ms |
24708 KB |
Output is correct |
53 |
Correct |
116 ms |
21704 KB |
Output is correct |
54 |
Correct |
170 ms |
26604 KB |
Output is correct |
55 |
Correct |
154 ms |
26236 KB |
Output is correct |
56 |
Correct |
119 ms |
23528 KB |
Output is correct |
57 |
Correct |
168 ms |
25700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9696 KB |
Output is correct |
3 |
Correct |
7 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9684 KB |
Output is correct |
5 |
Correct |
6 ms |
9684 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
6 ms |
9812 KB |
Output is correct |
8 |
Correct |
6 ms |
9812 KB |
Output is correct |
9 |
Correct |
5 ms |
9812 KB |
Output is correct |
10 |
Correct |
65 ms |
20592 KB |
Output is correct |
11 |
Correct |
77 ms |
22988 KB |
Output is correct |
12 |
Correct |
76 ms |
22716 KB |
Output is correct |
13 |
Correct |
95 ms |
23536 KB |
Output is correct |
14 |
Correct |
64 ms |
20832 KB |
Output is correct |
15 |
Correct |
69 ms |
20576 KB |
Output is correct |
16 |
Correct |
143 ms |
24908 KB |
Output is correct |
17 |
Correct |
141 ms |
24560 KB |
Output is correct |
18 |
Correct |
198 ms |
25388 KB |
Output is correct |
19 |
Correct |
116 ms |
22792 KB |
Output is correct |
20 |
Correct |
113 ms |
22896 KB |
Output is correct |
21 |
Correct |
120 ms |
23352 KB |
Output is correct |
22 |
Correct |
110 ms |
23264 KB |
Output is correct |
23 |
Correct |
106 ms |
23260 KB |
Output is correct |
24 |
Correct |
137 ms |
23508 KB |
Output is correct |
25 |
Correct |
113 ms |
22900 KB |
Output is correct |
26 |
Correct |
111 ms |
23180 KB |
Output is correct |
27 |
Correct |
145 ms |
22872 KB |
Output is correct |
28 |
Correct |
5 ms |
9812 KB |
Output is correct |
29 |
Correct |
6 ms |
9812 KB |
Output is correct |
30 |
Correct |
5 ms |
9812 KB |
Output is correct |
31 |
Correct |
5 ms |
9812 KB |
Output is correct |
32 |
Correct |
6 ms |
9812 KB |
Output is correct |
33 |
Correct |
6 ms |
9812 KB |
Output is correct |
34 |
Correct |
7 ms |
9812 KB |
Output is correct |
35 |
Correct |
5 ms |
9812 KB |
Output is correct |
36 |
Correct |
5 ms |
9812 KB |
Output is correct |
37 |
Correct |
13 ms |
11348 KB |
Output is correct |
38 |
Correct |
82 ms |
23544 KB |
Output is correct |
39 |
Correct |
85 ms |
23440 KB |
Output is correct |
40 |
Correct |
82 ms |
23208 KB |
Output is correct |
41 |
Correct |
89 ms |
22800 KB |
Output is correct |
42 |
Correct |
87 ms |
22624 KB |
Output is correct |
43 |
Correct |
93 ms |
21520 KB |
Output is correct |
44 |
Correct |
86 ms |
23548 KB |
Output is correct |
45 |
Correct |
95 ms |
23572 KB |
Output is correct |
46 |
Correct |
67 ms |
20936 KB |
Output is correct |
47 |
Correct |
80 ms |
22528 KB |
Output is correct |
48 |
Correct |
18 ms |
11604 KB |
Output is correct |
49 |
Correct |
173 ms |
25976 KB |
Output is correct |
50 |
Correct |
158 ms |
25816 KB |
Output is correct |
51 |
Correct |
144 ms |
25832 KB |
Output is correct |
52 |
Correct |
190 ms |
25528 KB |
Output is correct |
53 |
Correct |
140 ms |
24708 KB |
Output is correct |
54 |
Correct |
116 ms |
21704 KB |
Output is correct |
55 |
Correct |
170 ms |
26604 KB |
Output is correct |
56 |
Correct |
154 ms |
26236 KB |
Output is correct |
57 |
Correct |
119 ms |
23528 KB |
Output is correct |
58 |
Correct |
168 ms |
25700 KB |
Output is correct |
59 |
Correct |
66 ms |
15308 KB |
Output is correct |
60 |
Correct |
147 ms |
26080 KB |
Output is correct |
61 |
Correct |
162 ms |
25808 KB |
Output is correct |
62 |
Correct |
159 ms |
26716 KB |
Output is correct |
63 |
Correct |
120 ms |
24276 KB |
Output is correct |
64 |
Correct |
5 ms |
9812 KB |
Output is correct |
65 |
Correct |
6 ms |
9832 KB |
Output is correct |
66 |
Correct |
5 ms |
9812 KB |
Output is correct |
67 |
Correct |
5 ms |
9812 KB |
Output is correct |
68 |
Correct |
7 ms |
9760 KB |
Output is correct |
69 |
Correct |
6 ms |
9812 KB |
Output is correct |
70 |
Correct |
6 ms |
9812 KB |
Output is correct |
71 |
Correct |
7 ms |
9812 KB |
Output is correct |
72 |
Correct |
5 ms |
9812 KB |
Output is correct |
73 |
Correct |
8 ms |
9812 KB |
Output is correct |
74 |
Correct |
85 ms |
21348 KB |
Output is correct |
75 |
Correct |
95 ms |
23440 KB |
Output is correct |
76 |
Correct |
93 ms |
22340 KB |
Output is correct |
77 |
Correct |
82 ms |
21604 KB |
Output is correct |
78 |
Correct |
59 ms |
15404 KB |
Output is correct |
79 |
Correct |
50 ms |
14580 KB |
Output is correct |
80 |
Correct |
72 ms |
19412 KB |
Output is correct |
81 |
Correct |
121 ms |
25300 KB |
Output is correct |
82 |
Correct |
109 ms |
24468 KB |
Output is correct |
83 |
Correct |
128 ms |
27036 KB |
Output is correct |
84 |
Correct |
71 ms |
20980 KB |
Output is correct |
85 |
Correct |
102 ms |
23972 KB |
Output is correct |
86 |
Correct |
49 ms |
14572 KB |
Output is correct |
87 |
Correct |
158 ms |
25736 KB |
Output is correct |
88 |
Correct |
208 ms |
25708 KB |
Output is correct |
89 |
Correct |
131 ms |
23456 KB |
Output is correct |
90 |
Correct |
147 ms |
17832 KB |
Output is correct |
91 |
Correct |
123 ms |
18280 KB |
Output is correct |
92 |
Correct |
131 ms |
22216 KB |
Output is correct |
93 |
Correct |
182 ms |
27372 KB |
Output is correct |
94 |
Correct |
181 ms |
26848 KB |
Output is correct |
95 |
Correct |
190 ms |
28704 KB |
Output is correct |
96 |
Correct |
132 ms |
23656 KB |
Output is correct |
97 |
Correct |
164 ms |
25608 KB |
Output is correct |