#include "swap.h"
#include <bits/stdc++.h>
#define ii pair<int, int>
#define iii pair<int, ii>
#define fi first
#define se second
using namespace std;
const int N = 2e5 + 5;
int n, m, par[N], p1[N], p2[N], past[N], cur[N];
vector <iii> edg;
int root(int u)
{
return (par[u] < 0) ? u : par[u] = root(par[u]);
}
bool check(int u, int v, int mid)
{
while (par[u] > 0 && past[u] <= mid) u = par[u];
while (par[v] > 0 && past[v] <= mid) v = par[v];
if(u != v) return 0;
if(cur[u] && cur[u] <= mid) return 1;
return 0;
}
void join(int u, int v, int w)
{
u = root(u), v = root(v);
if(u == v)
{
if(!cur[u]) cur[u] = w;
return ;
}
if(par[u] > par[v]) swap(u, v);
par[u] += par[v];
past[v] = w;
if(par[v] == -1 && !cur[u])
{
if(p1[u] == u) p1[u] = v;
else if(p2[u] == u) p2[u] = v;
else cur[u] = w;
}
par[v] = u;
if(!cur[u] && !cur[v])
{
if(p1[u] == p1[v]) p1[u] = p2[v];
else if(p1[u] == p2[v]) p1[u] = p1[v];
else if(p2[u] == p1[v]) p2[u] = p2[v];
else if(p2[u] == p2[v]) p2[u] = p1[v];
else cur[u] = w;
}
else if(!cur[u]) cur[u] = w;
}
void init(int n, int m, vector <int> U, vector <int> V, vector <int> W)
{
for(int i = 1; i <= n; i++)
{
p1[i] = p2[i] = i;
par[i] = -1;
}
for(int i = 0; i < m; i++)
{
U[i]++, V[i]++;
edg.push_back({W[i], {U[i], V[i]}});
}
sort(edg.begin(), edg.end());
for(auto [w, e] : edg) join(e.fi, e.se, w);
}
int getMinimumFuelCapacity(int u, int v)
{
u++, v++;
int l = 1, r = edg[edg.size() - 1].fi, mid, ans = -1;
while (l <= r)
{
mid = (l + r) / 2;
if(check(u, v, mid)) ans = mid, r = mid - 1;
else l = mid + 1;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
149 ms |
11892 KB |
Output is correct |
4 |
Correct |
149 ms |
12060 KB |
Output is correct |
5 |
Correct |
153 ms |
12432 KB |
Output is correct |
6 |
Correct |
141 ms |
11964 KB |
Output is correct |
7 |
Correct |
153 ms |
12304 KB |
Output is correct |
8 |
Correct |
157 ms |
12012 KB |
Output is correct |
9 |
Correct |
150 ms |
12056 KB |
Output is correct |
10 |
Correct |
191 ms |
12024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |