This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// M
#include<bits/stdc++.h>
#include "game.h"
using namespace std;
const int N = 1509;
int n, P[N], C[N][N];
void initialize(int _n)
{
n = _n;
memset(P, -1, sizeof(P));
}
int Find(int v)
{
return (P[v] < 0 ? v : (P[v] = Find(P[v])));
}
inline void Merge(int v, int u)
{
v = Find(v);
u = Find(u);
assert(v != u);
C[v][u] = C[u][v] = 0;
for (int i = 0; i < n; i ++)
{
C[v][i] += C[u][i];
C[i][v] += C[u][i];
C[u][i] = C[i][u] = 0;
}
P[v] += P[u];
P[u] = v;
}
int hasEdge(int v, int u)
{
v = Find(v);
u = Find(u);
assert(v != u);
C[v][u] ++; C[u][v] ++;
if (C[v][u] == P[v] * P[u])
return Merge(v, u), 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... |