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 <bits/stdc++.h>
#include "game.h"
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
using namespace std;
int dsu[1510], rnk[1510];
set<pii> svi;
int root(int u)
{
while (u!=dsu[u])
{
dsu[u]=dsu[dsu[u]];
u=dsu[u];
}
return u;
}
void connect(int u, int v)
{
//if (root(u)==root(v)) return;
if (rnk[root(u)]<=rnk[root(v)])
{
if (rnk[root(u)]==rnk[root(v)]) rnk[root(v)]++;
dsu[root(u)]=root(v);
}
else
dsu[root(v)]=root(u);
}
void initialize(int n) {
for (int i=0; i<n; i++) for (int j=0; j<n; j++) if (i<j) svi.insert({i, j});
for (int i=0; i<n; i++) { dsu[i]=i; rnk[i]=1; }
}
int hasEdge(int u, int v) {
if (u>v) swap(u, v);
int ru, rv; ru=root(u); rv=root(v);
svi.erase({u, v});
bool moze=true;
for (auto par:svi)
{
int a, b; a=par.xx; b=par.yy;
//cout<<a<<" "<<b<<" "<<root(a)<<" "<<root(b)<<" "<<ru<<" "<<rv<<endl;
if ((root(a)==ru && root(b)==rv) || (root(a)==rv && root(b)==ru)) { moze=false; break; }
}
if (!moze) return 0;
connect(u, v);
return 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |