#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
struct node {
int endP[2], par, size, val;
} comp[MAXN];
int wpar[MAXN], depth[MAXN];
vector <int> adj[MAXN];
int root(int u) {
while (comp[u].par >= 0) u = comp[u].par;
return u;
}
bool join(int u, int v, int w) {
int x = root(u), y = root(v);
if (x == y) {
if (comp[x].val < 0) comp[x].val = w;
return false;
}
if (comp[x].size < comp[y].size) {
swap(x, y); swap(u, v);
}
comp[x].size += comp[y].size; comp[y].par = x;
wpar[y] = w; adj[x].push_back(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 {
int tmp = w;
if (comp[x].val >= 0)
tmp = min(tmp, comp[x].val);
if (comp[y].val >= 0)
tmp = min(tmp, comp[y].val);
comp[x].val = tmp;
}
return true;
}
void DFS(int u) {
for (int v : adj[u]) {
depth[v] = depth[u] + 1; DFS(v);
}
}
void init(int N, int M, vector <int> U,
vector <int> V, vector <int> W) {
vector <int> sorted(M);
iota(sorted.begin(), sorted.end(), 0);
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) u = comp[u].par;
if (u < 0) return -1;
return max(res, comp[u].val);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
52 ms |
8004 KB |
Output is correct |
10 |
Correct |
65 ms |
9140 KB |
Output is correct |
11 |
Correct |
68 ms |
9012 KB |
Output is correct |
12 |
Correct |
72 ms |
11496 KB |
Output is correct |
13 |
Correct |
54 ms |
10776 KB |
Output is correct |
14 |
Correct |
60 ms |
9952 KB |
Output is correct |
15 |
Correct |
167 ms |
15044 KB |
Output is correct |
16 |
Correct |
158 ms |
14868 KB |
Output is correct |
17 |
Correct |
163 ms |
15468 KB |
Output is correct |
18 |
Correct |
125 ms |
14592 KB |
Output is correct |
19 |
Correct |
79 ms |
9284 KB |
Output is correct |
20 |
Correct |
157 ms |
15952 KB |
Output is correct |
21 |
Correct |
158 ms |
16144 KB |
Output is correct |
22 |
Correct |
167 ms |
16580 KB |
Output is correct |
23 |
Correct |
129 ms |
15940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
118 ms |
11028 KB |
Output is correct |
4 |
Correct |
118 ms |
14876 KB |
Output is correct |
5 |
Correct |
121 ms |
15188 KB |
Output is correct |
6 |
Correct |
116 ms |
14812 KB |
Output is correct |
7 |
Correct |
122 ms |
15168 KB |
Output is correct |
8 |
Correct |
119 ms |
14844 KB |
Output is correct |
9 |
Correct |
119 ms |
14924 KB |
Output is correct |
10 |
Correct |
119 ms |
14732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
3 ms |
2636 KB |
Output is correct |
13 |
Correct |
2 ms |
2636 KB |
Output is correct |
14 |
Correct |
3 ms |
2672 KB |
Output is correct |
15 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
52 ms |
8004 KB |
Output is correct |
11 |
Correct |
65 ms |
9140 KB |
Output is correct |
12 |
Correct |
68 ms |
9012 KB |
Output is correct |
13 |
Correct |
72 ms |
11496 KB |
Output is correct |
14 |
Correct |
54 ms |
10776 KB |
Output is correct |
15 |
Correct |
2 ms |
2636 KB |
Output is correct |
16 |
Correct |
2 ms |
2636 KB |
Output is correct |
17 |
Correct |
3 ms |
2636 KB |
Output is correct |
18 |
Correct |
2 ms |
2636 KB |
Output is correct |
19 |
Correct |
3 ms |
2672 KB |
Output is correct |
20 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
52 ms |
8004 KB |
Output is correct |
10 |
Correct |
65 ms |
9140 KB |
Output is correct |
11 |
Correct |
68 ms |
9012 KB |
Output is correct |
12 |
Correct |
72 ms |
11496 KB |
Output is correct |
13 |
Correct |
54 ms |
10776 KB |
Output is correct |
14 |
Correct |
60 ms |
9952 KB |
Output is correct |
15 |
Correct |
167 ms |
15044 KB |
Output is correct |
16 |
Correct |
158 ms |
14868 KB |
Output is correct |
17 |
Correct |
163 ms |
15468 KB |
Output is correct |
18 |
Correct |
125 ms |
14592 KB |
Output is correct |
19 |
Correct |
118 ms |
11028 KB |
Output is correct |
20 |
Correct |
118 ms |
14876 KB |
Output is correct |
21 |
Correct |
121 ms |
15188 KB |
Output is correct |
22 |
Correct |
116 ms |
14812 KB |
Output is correct |
23 |
Correct |
122 ms |
15168 KB |
Output is correct |
24 |
Correct |
119 ms |
14844 KB |
Output is correct |
25 |
Correct |
119 ms |
14924 KB |
Output is correct |
26 |
Correct |
119 ms |
14732 KB |
Output is correct |
27 |
Correct |
2 ms |
2636 KB |
Output is correct |
28 |
Correct |
2 ms |
2636 KB |
Output is correct |
29 |
Correct |
3 ms |
2636 KB |
Output is correct |
30 |
Correct |
2 ms |
2636 KB |
Output is correct |
31 |
Correct |
3 ms |
2672 KB |
Output is correct |
32 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
52 ms |
8004 KB |
Output is correct |
11 |
Correct |
65 ms |
9140 KB |
Output is correct |
12 |
Correct |
68 ms |
9012 KB |
Output is correct |
13 |
Correct |
72 ms |
11496 KB |
Output is correct |
14 |
Correct |
54 ms |
10776 KB |
Output is correct |
15 |
Correct |
60 ms |
9952 KB |
Output is correct |
16 |
Correct |
167 ms |
15044 KB |
Output is correct |
17 |
Correct |
158 ms |
14868 KB |
Output is correct |
18 |
Correct |
163 ms |
15468 KB |
Output is correct |
19 |
Correct |
125 ms |
14592 KB |
Output is correct |
20 |
Correct |
118 ms |
11028 KB |
Output is correct |
21 |
Correct |
118 ms |
14876 KB |
Output is correct |
22 |
Correct |
121 ms |
15188 KB |
Output is correct |
23 |
Correct |
116 ms |
14812 KB |
Output is correct |
24 |
Correct |
122 ms |
15168 KB |
Output is correct |
25 |
Correct |
119 ms |
14844 KB |
Output is correct |
26 |
Correct |
119 ms |
14924 KB |
Output is correct |
27 |
Correct |
119 ms |
14732 KB |
Output is correct |
28 |
Correct |
2 ms |
2636 KB |
Output is correct |
29 |
Correct |
2 ms |
2636 KB |
Output is correct |
30 |
Correct |
3 ms |
2636 KB |
Output is correct |
31 |
Correct |
2 ms |
2636 KB |
Output is correct |
32 |
Correct |
3 ms |
2672 KB |
Output is correct |
33 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |