void initialize(int n);
int hasEdge(int u, int v);
const int N = 1001;
int n, mp[N][N], par[N];
int root(int x) {
return x == par[x] ? x : par[x] = root(par[x]);
}
void merge(int u, int v) {
u = root(u), v = root(v);
if (u == v) return;
par[v] = u;
}
void initialize(int cnt)
{
n = cnt;
for (int i = 1; i <= cnt; i++)
for (int j = 1; j <= cnt; j++)
mp[i][j] = 0;
for (int i = 1; i <= cnt; i++)
par[i] = i;
}
int hasEdge(int u, int v)
{
if (u > v) {
int tmp = u;
u = v;
v = tmp;
}
if (root(u) == root(v))
return 1;
mp[u][v]++;
if (mp[u][v] == n-1) {
merge(u, v);
return 1;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 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 |
- |