이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
class UnionFind {
public:
vector<int>par;
void init(int sz) {
par.resize(sz, -1);
}
int root(int pos) {
if (par[pos] == -1) return pos;
par[pos] = root(par[pos]);
return par[pos];
}
void unite(int u, int v) {
u = root(u); v = root(v);
if (u == v) return;
par[u] = v;
}
bool same(int u, int v) {
if (root(u) == root(v)) return true;
return false;
}
};
int N; bool c[108][108];
void initialize(int n) {
N = n;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) c[i][j] = true;
}
}
bool IsConnected() {
UnionFind UF; UF.init(N); int cnts = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (c[i][j] == true && UF.same(i, j) == false) {
UF.unite(i, j); cnts++;
}
}
}
if (cnts == N - 1) return true;
return false;
}
int hasEdge(int u, int v) {
if (u > v) swap(u, v);
c[u][v] = false;
if (IsConnected() == false) { c[u][v] = true; return 1; }
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... |