#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
#define all(a) begin(a),end(a)
#define sz(a) (int)a.size()
#define pb push_back
const int mxN = (int)3e5+10;
int n, m, deg[mxN];
int p[mxN], cycle[mxN], line[mxN];
vector<array<int,3>> edges;
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
n = N, m = M;
for(int i = 0; i < M; i++)
edges.pb({W[i],U[i],V[i]});
sort(all(edges),[&](array<int,3> a, array<int,3> b){
return a[0]<b[0];
});
}
int findSet(int i){return p[i]==i?i:p[i]=findSet(p[i]);}
bool isSameSet(int i, int j) { return findSet(i)==findSet(j); }
void unionSet(int i, int j){
deg[i]++, deg[j]++;
int x = findSet(i), y = findSet(j);
if(x==y){
cycle[x] = true;
return;
}
if(!line[x] or !line[y] or deg[i]>=3 or deg[j]>=3)
line[x]=line[y]=0;
p[y] = x;
}
bool check(int x, int s, int t){
for(int i = 0; i <= x; i++)
unionSet(edges[i][1],edges[i][2]);
if(!isSameSet(s,t)) return false;
int set = findSet(s);
return cycle[set] or !line[set];
}
int getMinimumFuelCapacity(int X, int Y) {
int l = 0, r = m-1;
if(!check(r,X,Y)) return -1;
while(l<r){
for(int i = 0; i < n; i++)
p[i]=i,cycle[i]=0,deg[i]=0,line[i]=1;
int mid = (l+r)/2;
if(check(mid,X,Y)) r=mid;
else l=mid+1;
}
return edges[l][0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |