#include <bits/stdc++.h>
#include "swap.h"
#define ff first
#define ss second
using namespace std;
typedef pair<int, int> pii;
const int maxn = 2e5+10;
const int inf = 1e9+10;
int n;
int mn3[maxn];
int ans[maxn];
int D[maxn], par[maxn];
bool mark[maxn];
vector<pii> grafo[maxn];
struct Edge
{
int u, v, w;
} edge[maxn];
struct DSU
{
int pai[maxn], peso[maxn], nivel[maxn], val[maxn], tt[maxn];
void init(int n)
{
for (int i = 1; i <= n; i++)
{
pai[i] = i, peso[i] = 1, nivel[i] = 0;
if (grafo[i].size() >= 3) val[i] = mn3[i];
else val[i] = inf;
}
}
int Find(int x)
{
if (pai[x] == x) return x;
return Find(pai[x]);
}
void Join(int x, int y, int t)
{
x = Find(x), y = Find(y);
if (x == y) return;
if (peso[x] < peso[y]) swap(x, y);
pai[y] = x, peso[x] += peso[y], tt[y] = t;
}
void dfs(int u)
{
if (u == Find(u))
{
nivel[u] = 1;
return;
}
if (!nivel[pai[u]]) dfs(pai[u]);
nivel[u] = nivel[pai[u]]+1;
}
void upd(int u)
{
int v = u;
int mx = 0;
while (true)
{
val[v] = min(val[v], max(mn3[u], mx));
if (pai[v] == v) return;
mx = max(mx, tt[v]);
v = pai[v];
}
}
int get(int u)
{
int v = u, ans = inf, mx = 0;
while (true)
{
ans = min(ans, max(mx, val[v]));
if (v == pai[v]) return ans;
mx = max(mx, tt[v]);
v = pai[v];
}
}
int get_mx(int u, int v)
{
int ans = 0;
while (u != v)
{
if (nivel[u] > nivel[v])
{
ans = max(ans, tt[u]);
u = pai[u];
}
else
{
ans = max(ans, tt[v]);
v = pai[v];
}
}
return ans;
}
} dsu;
void init(int N, int m, vector<int> U, vector<int> V, vector<int> W)
{
n = N;
for (int i = 0; i < m; i++)
{
grafo[U[i]+1].push_back({V[i]+1, W[i]});
grafo[V[i]+1].push_back({U[i]+1, W[i]});
edge[i+1] = {U[i]+1, V[i]+1, W[i]};
}
sort(edge+1, edge+m+1, [&] (Edge a, Edge b) {return a.w < b.w;});
for (int i = 1; i <= n; i++)
{
sort(grafo[i].begin(), grafo[i].end(), [&] (pii a, pii b) {return a.ss < b.ss;});
if (grafo[i].size() <= 2) mn3[i] = inf;
else mn3[i] = grafo[i][2].ss;
}
dsu.init(n);
for (int i = 1; i <= m; i++)
{
if (dsu.Find(edge[i].u) == dsu.Find(edge[i].v))
{
mn3[edge[i].u] = min(mn3[edge[i].u], edge[i].w);
mn3[edge[i].v] = min(mn3[edge[i].v], edge[i].w);
}
dsu.Join(edge[i].u, edge[i].v, edge[i].w);
}
for (int i = 1; i <= n; i++)
{
if (mn3[i] != inf)
dsu.upd(i);
if (!dsu.nivel[i])
dsu.dfs(i);
}
}
int getMinimumFuelCapacity(int u, int v)
{
u++, v++;
if (u == v) return -1;
if (min(dsu.get(u), dsu.get(v)) == inf) return -1;
return max(min(dsu.get(u), dsu.get(v)), dsu.get_mx(u, v));
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
4 ms |
5120 KB |
Output is correct |
7 |
Correct |
4 ms |
5120 KB |
Output is correct |
8 |
Correct |
4 ms |
5120 KB |
Output is correct |
9 |
Correct |
73 ms |
12152 KB |
Output is correct |
10 |
Correct |
90 ms |
13688 KB |
Output is correct |
11 |
Correct |
91 ms |
13560 KB |
Output is correct |
12 |
Correct |
99 ms |
14072 KB |
Output is correct |
13 |
Correct |
93 ms |
14072 KB |
Output is correct |
14 |
Correct |
81 ms |
12280 KB |
Output is correct |
15 |
Correct |
184 ms |
15640 KB |
Output is correct |
16 |
Correct |
183 ms |
15396 KB |
Output is correct |
17 |
Correct |
190 ms |
15836 KB |
Output is correct |
18 |
Correct |
167 ms |
15840 KB |
Output is correct |
19 |
Correct |
98 ms |
9976 KB |
Output is correct |
20 |
Correct |
221 ms |
16728 KB |
Output is correct |
21 |
Correct |
202 ms |
16688 KB |
Output is correct |
22 |
Correct |
209 ms |
17248 KB |
Output is correct |
23 |
Correct |
179 ms |
17372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
158 ms |
17424 KB |
Output is correct |
4 |
Correct |
157 ms |
17620 KB |
Output is correct |
5 |
Correct |
162 ms |
17668 KB |
Output is correct |
6 |
Correct |
155 ms |
17620 KB |
Output is correct |
7 |
Correct |
159 ms |
17772 KB |
Output is correct |
8 |
Correct |
157 ms |
17436 KB |
Output is correct |
9 |
Correct |
159 ms |
17516 KB |
Output is correct |
10 |
Correct |
161 ms |
17320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
3 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
4 ms |
5120 KB |
Output is correct |
7 |
Correct |
4 ms |
5120 KB |
Output is correct |
8 |
Correct |
4 ms |
5120 KB |
Output is correct |
9 |
Correct |
4 ms |
5120 KB |
Output is correct |
10 |
Correct |
4 ms |
5120 KB |
Output is correct |
11 |
Correct |
4 ms |
5120 KB |
Output is correct |
12 |
Correct |
5 ms |
5120 KB |
Output is correct |
13 |
Correct |
5 ms |
5120 KB |
Output is correct |
14 |
Correct |
4 ms |
5120 KB |
Output is correct |
15 |
Correct |
4 ms |
5120 KB |
Output is correct |
16 |
Correct |
4 ms |
5120 KB |
Output is correct |
17 |
Correct |
5 ms |
5120 KB |
Output is correct |
18 |
Correct |
4 ms |
5120 KB |
Output is correct |
19 |
Correct |
4 ms |
5120 KB |
Output is correct |
20 |
Correct |
4 ms |
5120 KB |
Output is correct |
21 |
Correct |
4 ms |
5120 KB |
Output is correct |
22 |
Correct |
5 ms |
5120 KB |
Output is correct |
23 |
Correct |
4 ms |
5120 KB |
Output is correct |
24 |
Correct |
5 ms |
5248 KB |
Output is correct |
25 |
Correct |
6 ms |
5248 KB |
Output is correct |
26 |
Correct |
5 ms |
5248 KB |
Output is correct |
27 |
Correct |
4 ms |
5120 KB |
Output is correct |
28 |
Correct |
5 ms |
5248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
3 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
4 ms |
5120 KB |
Output is correct |
7 |
Correct |
4 ms |
5120 KB |
Output is correct |
8 |
Correct |
4 ms |
5120 KB |
Output is correct |
9 |
Correct |
4 ms |
5120 KB |
Output is correct |
10 |
Correct |
73 ms |
12152 KB |
Output is correct |
11 |
Correct |
90 ms |
13688 KB |
Output is correct |
12 |
Correct |
91 ms |
13560 KB |
Output is correct |
13 |
Correct |
99 ms |
14072 KB |
Output is correct |
14 |
Correct |
93 ms |
14072 KB |
Output is correct |
15 |
Correct |
4 ms |
5120 KB |
Output is correct |
16 |
Correct |
4 ms |
5120 KB |
Output is correct |
17 |
Correct |
5 ms |
5120 KB |
Output is correct |
18 |
Correct |
5 ms |
5120 KB |
Output is correct |
19 |
Correct |
4 ms |
5120 KB |
Output is correct |
20 |
Correct |
4 ms |
5120 KB |
Output is correct |
21 |
Correct |
4 ms |
5120 KB |
Output is correct |
22 |
Correct |
5 ms |
5120 KB |
Output is correct |
23 |
Correct |
4 ms |
5120 KB |
Output is correct |
24 |
Correct |
14 ms |
6400 KB |
Output is correct |
25 |
Correct |
89 ms |
14072 KB |
Output is correct |
26 |
Correct |
94 ms |
14072 KB |
Output is correct |
27 |
Correct |
89 ms |
14056 KB |
Output is correct |
28 |
Correct |
87 ms |
13944 KB |
Output is correct |
29 |
Correct |
89 ms |
13900 KB |
Output is correct |
30 |
Correct |
82 ms |
13348 KB |
Output is correct |
31 |
Correct |
106 ms |
14076 KB |
Output is correct |
32 |
Correct |
96 ms |
14072 KB |
Output is correct |
33 |
Correct |
89 ms |
14072 KB |
Output is correct |
34 |
Correct |
100 ms |
14568 KB |
Output is correct |
35 |
Correct |
4 ms |
5120 KB |
Output is correct |
36 |
Correct |
4 ms |
5120 KB |
Output is correct |
37 |
Correct |
4 ms |
5120 KB |
Output is correct |
38 |
Correct |
5 ms |
5120 KB |
Output is correct |
39 |
Correct |
4 ms |
5120 KB |
Output is correct |
40 |
Correct |
5 ms |
5248 KB |
Output is correct |
41 |
Correct |
6 ms |
5248 KB |
Output is correct |
42 |
Correct |
5 ms |
5248 KB |
Output is correct |
43 |
Correct |
4 ms |
5120 KB |
Output is correct |
44 |
Correct |
5 ms |
5248 KB |
Output is correct |
45 |
Correct |
149 ms |
17016 KB |
Output is correct |
46 |
Correct |
92 ms |
14072 KB |
Output is correct |
47 |
Correct |
96 ms |
14072 KB |
Output is correct |
48 |
Correct |
106 ms |
14712 KB |
Output is correct |
49 |
Correct |
112 ms |
15608 KB |
Output is correct |
50 |
Correct |
92 ms |
12792 KB |
Output is correct |
51 |
Correct |
119 ms |
15096 KB |
Output is correct |
52 |
Correct |
166 ms |
18304 KB |
Output is correct |
53 |
Correct |
183 ms |
19452 KB |
Output is correct |
54 |
Correct |
206 ms |
20728 KB |
Output is correct |
55 |
Correct |
87 ms |
14076 KB |
Output is correct |
56 |
Correct |
169 ms |
18936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
4 ms |
5120 KB |
Output is correct |
7 |
Correct |
4 ms |
5120 KB |
Output is correct |
8 |
Correct |
4 ms |
5120 KB |
Output is correct |
9 |
Correct |
73 ms |
12152 KB |
Output is correct |
10 |
Correct |
90 ms |
13688 KB |
Output is correct |
11 |
Correct |
91 ms |
13560 KB |
Output is correct |
12 |
Correct |
99 ms |
14072 KB |
Output is correct |
13 |
Correct |
93 ms |
14072 KB |
Output is correct |
14 |
Correct |
81 ms |
12280 KB |
Output is correct |
15 |
Correct |
184 ms |
15640 KB |
Output is correct |
16 |
Correct |
183 ms |
15396 KB |
Output is correct |
17 |
Correct |
190 ms |
15836 KB |
Output is correct |
18 |
Correct |
167 ms |
15840 KB |
Output is correct |
19 |
Correct |
158 ms |
17424 KB |
Output is correct |
20 |
Correct |
157 ms |
17620 KB |
Output is correct |
21 |
Correct |
162 ms |
17668 KB |
Output is correct |
22 |
Correct |
155 ms |
17620 KB |
Output is correct |
23 |
Correct |
159 ms |
17772 KB |
Output is correct |
24 |
Correct |
157 ms |
17436 KB |
Output is correct |
25 |
Correct |
159 ms |
17516 KB |
Output is correct |
26 |
Correct |
161 ms |
17320 KB |
Output is correct |
27 |
Correct |
4 ms |
5120 KB |
Output is correct |
28 |
Correct |
4 ms |
5120 KB |
Output is correct |
29 |
Correct |
5 ms |
5120 KB |
Output is correct |
30 |
Correct |
5 ms |
5120 KB |
Output is correct |
31 |
Correct |
4 ms |
5120 KB |
Output is correct |
32 |
Correct |
4 ms |
5120 KB |
Output is correct |
33 |
Correct |
4 ms |
5120 KB |
Output is correct |
34 |
Correct |
5 ms |
5120 KB |
Output is correct |
35 |
Correct |
4 ms |
5120 KB |
Output is correct |
36 |
Correct |
14 ms |
6400 KB |
Output is correct |
37 |
Correct |
89 ms |
14072 KB |
Output is correct |
38 |
Correct |
94 ms |
14072 KB |
Output is correct |
39 |
Correct |
89 ms |
14056 KB |
Output is correct |
40 |
Correct |
87 ms |
13944 KB |
Output is correct |
41 |
Correct |
89 ms |
13900 KB |
Output is correct |
42 |
Correct |
82 ms |
13348 KB |
Output is correct |
43 |
Correct |
106 ms |
14076 KB |
Output is correct |
44 |
Correct |
96 ms |
14072 KB |
Output is correct |
45 |
Correct |
89 ms |
14072 KB |
Output is correct |
46 |
Correct |
100 ms |
14568 KB |
Output is correct |
47 |
Correct |
23 ms |
6560 KB |
Output is correct |
48 |
Correct |
205 ms |
16604 KB |
Output is correct |
49 |
Correct |
209 ms |
16764 KB |
Output is correct |
50 |
Correct |
203 ms |
16604 KB |
Output is correct |
51 |
Correct |
198 ms |
16624 KB |
Output is correct |
52 |
Correct |
195 ms |
16424 KB |
Output is correct |
53 |
Correct |
163 ms |
14952 KB |
Output is correct |
54 |
Correct |
220 ms |
17244 KB |
Output is correct |
55 |
Correct |
205 ms |
16604 KB |
Output is correct |
56 |
Correct |
174 ms |
16792 KB |
Output is correct |
57 |
Correct |
218 ms |
17760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
3 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
4 ms |
5120 KB |
Output is correct |
7 |
Correct |
4 ms |
5120 KB |
Output is correct |
8 |
Correct |
4 ms |
5120 KB |
Output is correct |
9 |
Correct |
4 ms |
5120 KB |
Output is correct |
10 |
Correct |
73 ms |
12152 KB |
Output is correct |
11 |
Correct |
90 ms |
13688 KB |
Output is correct |
12 |
Correct |
91 ms |
13560 KB |
Output is correct |
13 |
Correct |
99 ms |
14072 KB |
Output is correct |
14 |
Correct |
93 ms |
14072 KB |
Output is correct |
15 |
Correct |
81 ms |
12280 KB |
Output is correct |
16 |
Correct |
184 ms |
15640 KB |
Output is correct |
17 |
Correct |
183 ms |
15396 KB |
Output is correct |
18 |
Correct |
190 ms |
15836 KB |
Output is correct |
19 |
Correct |
167 ms |
15840 KB |
Output is correct |
20 |
Correct |
158 ms |
17424 KB |
Output is correct |
21 |
Correct |
157 ms |
17620 KB |
Output is correct |
22 |
Correct |
162 ms |
17668 KB |
Output is correct |
23 |
Correct |
155 ms |
17620 KB |
Output is correct |
24 |
Correct |
159 ms |
17772 KB |
Output is correct |
25 |
Correct |
157 ms |
17436 KB |
Output is correct |
26 |
Correct |
159 ms |
17516 KB |
Output is correct |
27 |
Correct |
161 ms |
17320 KB |
Output is correct |
28 |
Correct |
4 ms |
5120 KB |
Output is correct |
29 |
Correct |
4 ms |
5120 KB |
Output is correct |
30 |
Correct |
5 ms |
5120 KB |
Output is correct |
31 |
Correct |
5 ms |
5120 KB |
Output is correct |
32 |
Correct |
4 ms |
5120 KB |
Output is correct |
33 |
Correct |
4 ms |
5120 KB |
Output is correct |
34 |
Correct |
4 ms |
5120 KB |
Output is correct |
35 |
Correct |
5 ms |
5120 KB |
Output is correct |
36 |
Correct |
4 ms |
5120 KB |
Output is correct |
37 |
Correct |
14 ms |
6400 KB |
Output is correct |
38 |
Correct |
89 ms |
14072 KB |
Output is correct |
39 |
Correct |
94 ms |
14072 KB |
Output is correct |
40 |
Correct |
89 ms |
14056 KB |
Output is correct |
41 |
Correct |
87 ms |
13944 KB |
Output is correct |
42 |
Correct |
89 ms |
13900 KB |
Output is correct |
43 |
Correct |
82 ms |
13348 KB |
Output is correct |
44 |
Correct |
106 ms |
14076 KB |
Output is correct |
45 |
Correct |
96 ms |
14072 KB |
Output is correct |
46 |
Correct |
89 ms |
14072 KB |
Output is correct |
47 |
Correct |
100 ms |
14568 KB |
Output is correct |
48 |
Correct |
23 ms |
6560 KB |
Output is correct |
49 |
Correct |
205 ms |
16604 KB |
Output is correct |
50 |
Correct |
209 ms |
16764 KB |
Output is correct |
51 |
Correct |
203 ms |
16604 KB |
Output is correct |
52 |
Correct |
198 ms |
16624 KB |
Output is correct |
53 |
Correct |
195 ms |
16424 KB |
Output is correct |
54 |
Correct |
163 ms |
14952 KB |
Output is correct |
55 |
Correct |
220 ms |
17244 KB |
Output is correct |
56 |
Correct |
205 ms |
16604 KB |
Output is correct |
57 |
Correct |
174 ms |
16792 KB |
Output is correct |
58 |
Correct |
218 ms |
17760 KB |
Output is correct |
59 |
Correct |
98 ms |
9976 KB |
Output is correct |
60 |
Correct |
221 ms |
16728 KB |
Output is correct |
61 |
Correct |
202 ms |
16688 KB |
Output is correct |
62 |
Correct |
209 ms |
17248 KB |
Output is correct |
63 |
Correct |
179 ms |
17372 KB |
Output is correct |
64 |
Correct |
4 ms |
5120 KB |
Output is correct |
65 |
Correct |
4 ms |
5120 KB |
Output is correct |
66 |
Correct |
4 ms |
5120 KB |
Output is correct |
67 |
Correct |
5 ms |
5120 KB |
Output is correct |
68 |
Correct |
4 ms |
5120 KB |
Output is correct |
69 |
Correct |
5 ms |
5248 KB |
Output is correct |
70 |
Correct |
6 ms |
5248 KB |
Output is correct |
71 |
Correct |
5 ms |
5248 KB |
Output is correct |
72 |
Correct |
4 ms |
5120 KB |
Output is correct |
73 |
Correct |
5 ms |
5248 KB |
Output is correct |
74 |
Correct |
149 ms |
17016 KB |
Output is correct |
75 |
Correct |
92 ms |
14072 KB |
Output is correct |
76 |
Correct |
96 ms |
14072 KB |
Output is correct |
77 |
Correct |
106 ms |
14712 KB |
Output is correct |
78 |
Correct |
112 ms |
15608 KB |
Output is correct |
79 |
Correct |
92 ms |
12792 KB |
Output is correct |
80 |
Correct |
119 ms |
15096 KB |
Output is correct |
81 |
Correct |
166 ms |
18304 KB |
Output is correct |
82 |
Correct |
183 ms |
19452 KB |
Output is correct |
83 |
Correct |
206 ms |
20728 KB |
Output is correct |
84 |
Correct |
87 ms |
14076 KB |
Output is correct |
85 |
Correct |
169 ms |
18936 KB |
Output is correct |
86 |
Correct |
69 ms |
9772 KB |
Output is correct |
87 |
Correct |
207 ms |
16604 KB |
Output is correct |
88 |
Correct |
201 ms |
16604 KB |
Output is correct |
89 |
Correct |
184 ms |
16660 KB |
Output is correct |
90 |
Correct |
200 ms |
17232 KB |
Output is correct |
91 |
Correct |
196 ms |
16796 KB |
Output is correct |
92 |
Correct |
209 ms |
17752 KB |
Output is correct |
93 |
Correct |
282 ms |
20660 KB |
Output is correct |
94 |
Correct |
280 ms |
21504 KB |
Output is correct |
95 |
Correct |
314 ms |
22264 KB |
Output is correct |
96 |
Correct |
174 ms |
16736 KB |
Output is correct |
97 |
Correct |
230 ms |
19516 KB |
Output is correct |