This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "game.h"
#include <bits/stdc++.h>
#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;
template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
return a < b ? (a = b, true) : false;
}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int cur_n;
vector <vector <int>> mat;
vector <int> p;
int root(int u)
{
return p[u] < 0 ? u : p[u] = root(p[u]);
}
void initialize(int n)
{
mat.assign(n, vector <int> (n));
p.assign(n, -1);
cur_n = n;
}
int hasEdge(int u, int v)
{
u = root(u);
v = root(v);
if (u == v)
{
return 0;
}
if (p[u] > p[v])
{
swap(u, v);
}
mat[u][v]++;
mat[v][u]++;
if (mat[u][v] == p[u] * p[v])
{
//yes
//merge u and v
p[u] += p[v];
p[v] = u;
for (int i = 0; i < cur_n; i++)
{
mat[u][i] += mat[v][i];
mat[i][u] += mat[i][v];
}
mat[u][u] = mat[v][v] = mat[u][v] = mat[v][u] = 0;
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... |