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>
typedef long long ll;
typedef long double ld;
using namespace std;
//#define int long long
#define F first
#define S second
#define pii pair<int,int>
#define mpr make_pair
const int inf = 1e9;
const int maxn = 1510;
const int mod = 1e9+7;
int n;
int pors[maxn][maxn], par[maxn], sz[maxn];
int get_par(int v)
{
if(par[v] == -1) return v;
return (par[v] = get_par(par[v]));
}
bool ans;
void dsu(int u, int v)
{
u = get_par(u);
v = get_par(v);
if(sz[v] < sz[u]) swap(u,v);
ans = 0;
if(u == v) return;
pors[u][v]++;
pors[v][u]++;
if(pors[u][v] == (sz[v] * sz[u]))
{
for(int i = 1; i <= n; i++)
{
if(par[i] == -1 && i != u && i != v)
{
pors[v][i] += pors[u][i];
pors[i][v] += pors[u][i];
}
}
ans = 1;
sz[v] += sz[u];
par[u] = v;
}
}
void initialize(int N) {
n = N;
for(int i = 0; i < maxn; i++)
{
par[i] = -1;
sz[i] = 1;
}
}
int hasEdge(int u, int v) {
dsu(u,v);
return ans;
}
/*signed main()
{
//ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
initialize(5);
cout<< hasEdge(0,1) <<"\n";
cout<< hasEdge(0,2) <<"\n";
cout<< hasEdge(0,3) <<"\n";
cout<< hasEdge(0,4) <<"\n";
cout<< hasEdge(1,2) <<"\n";
cout<< hasEdge(1,3) <<"\n";
cout<< hasEdge(1,4) <<"\n";
cout<< hasEdge(2,3) <<"\n";
cout<< hasEdge(2,4) <<"\n";
cout<< hasEdge(3,4) <<"\n";
}*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |