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>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define f first
#define s second
#define pb push_back
typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
const int MAXN = 1510;
int n;
int par[MAXN], sz[MAXN];
int find (int a) {return par[a] = par[a]==a ? a : find(par[a]);}
bool same (int a, int b) {return find(a) == find(b);}
void unite (int a, int b) {
a = find(a), b = find(b);
if (a == b) return;
if (sz[b] > sz[a]) swap(a,b);
par[b] = a;
sz[a] += sz[b];
}
void resetDsu () {
FOR(i, 0, n-1) par[i] = i, sz[i] = 1;
}
unordered_set<int> remEdges;
unordered_set<int> added;
void initialize(int _n) {
n = _n;
FOR(i, 0, n-1) FOR(j, i+1, n-1)
remEdges.insert(i*n + j);
}
int hasEdge(int u, int v) {
if (u > v) swap(u, v);
remEdges.erase(u*n + v);
resetDsu();
for (int e : remEdges) {
int uu = e%n;
int vv = e/n;
unite(uu,vv);
}
for (int e : added) {
int uu = e%n;
int vv = e/n;
unite(uu,vv);
}
if (sz[find(0)] == n) return 0;
else {
added.insert(u*n + v);
return 1;
}
//return 1;
}
/*
4
0 1
3 0
1 2
0 2
3 1
2 3
4
0 3
2 0
0 1
1 2
1 3
2 3
4
0 3
1 0
0 2
3 1
1 2
2 3
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |