이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1500;
int parents[N];
set<pair<int, int>> links[N];
int find(int v) {
if (v == parents[v])
return v;
return parents[v] = find(parents[v]);
}
void merge(int a, int b) {
a = find(a);
b = find(b);
if (a != b)
parents[b] = a;
}
void initialize(int n) {
for (int i = 0; i < n; ++i) {
parents[i] = i;
for (int j = 0; j < n; ++j) {
if (i != j)
links[i].emplace(i, j);
}
}
}
int hasEdge(int u, int v) {
int c1 = find(u);
int c2 = find(v);
if (c1 == c2)
return 1;
links[c1].erase({u, v});
links[c2].erase({v, u});
queue<int> q({c1, c2});
while (!q.empty()) {
int c = find(q.front());
if (links[c].size() == 1) {
int self, other;
tie(self, other) = *links[c].begin();
int other_c = find(other);
merge(c, other_c);
links[other_c].erase({other, self});
links[c] = move(links[other_c]);
} else {
q.pop();
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |