#include "island.h"
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
pii upa[100000];
int rnk[100000], cnt;
int fnd(int x, int t) { return upa[x].second < t ? x : fnd(upa[x].first, t); }
void uni(int x, int y, int t) {
x = fnd(x, t), y = fnd(y, t);
if (x == y) return;
if (rnk[x] < rnk[y]) swap(x, y);
upa[y] = {x, t};
if (rnk[x] == rnk[y]) rnk[x]++;
}
int N, M;
void Init(int K, std::vector<int> F, std::vector<int> S, std::vector<int> E){
N = F.size(), M = S.size();
for (int i = 0; i < N; ++i) upa[i] = {i, -1};
for (int i = 0; i < M; ++i) uni(F[S[i]], F[E[i]], i);
}
int Separate(int A, int B){
int l = 0, r = M;
while (l < r) {
int m = l + r >> 1;
if (fnd(A, m) == fnd(B, m)) r = m;
else l = m + 1;
}
return l;
}
Compilation message
island.cpp: In function 'int Separate(int, int)':
island.cpp:28:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = l + r >> 1;
~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
148 ms |
7524 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |