#include "game.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
const int N = 1500+100, M = 1e5+10, K = 52, MX = 30;
struct Dsu {
vector<int> s, p;
int sz;
Dsu(int n){
sz = n;
s.resize(n, 1);
p.resize(n);
for(int i = 0; i < n; ++i) p[i] = i;
}
int find(int v){
if(p[v] == v) return v;
return (p[v] = find(p[v]));
}
void merge(int a, int b){
a = find(a);
b = find(b);
if(a != b){
if(s[a] > s[b]){
swap(a, b);
}
s[b] += s[a];
p[a] = b;
sz--;
}
}
};
vector<int> c;
int nn = 0;
set<pii> S;
void initialize(int n) {
c.clear();
c.resize(n, n-1);
nn =n;
S.clear();
for(int j = 0; j < n; ++j) for(int i = j + 1; i < n; ++i) S.insert({j, i});
}
int check(int u, int v){
Dsu d(nn);
for(auto [x, y]: S){
if(x == u && y == v) continue;
d.merge(x, y);
}
return d.sz == 1;
}
int hasEdge(int u, int v) {
if(u > v) swap(u, v);
if(check(u, v) == 0){
return 1;
}
S.erase(pii{u, v});
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... |