This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//by szh
#include "game.h"
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
const int maxn = 1555;
int n;
int f[maxn];
int sz[maxn];
int cnt[maxn][maxn];
int cntt[maxn];
set <int> s;
void initialize(int N) {
n = N;
rep(i,0,n) f[i]=i,sz[i]=1,s.insert(i);
memset(cnt,0,sizeof(cnt));
memset(cntt,0,sizeof(cntt));
return;
}
int getf(int u) {
if (f[u]==u) return u;
else return f[u] = getf(f[u]);
}
int what = 0;
bool check(int rt) {
// debug(sz[rt]*(n-sz[rt])); debug(cntt[rt]);
if (sz[rt]*(n-sz[rt])-1==cntt[rt]) return true;
else return false;
}
int hasEdge(int u,int v) {
int fu = getf(u),fv = getf(v);
if (fu==fv) return 0;
if (check(fu) or check(fv)) {
f[fu] = fv;
sz[fv] += sz[fu];
s.erase(fu);
cntt[fv]=0;
for (auto it:s) {
if (it==fv) continue;
cnt[fv][it] += cnt[fu][it];
cnt[it][fv] += cnt[fu][it];
assert(cnt[it][fv]==cnt[fv][it]);
cntt[fv] += cnt[fv][it];
}
what++;
assert(what<n);
return 1;
}
else {
cnt[u][v]++;
cnt[v][u]++;
cntt[u]++;
cntt[v]++;
return 0;
}
}
/*
int read_int() {
int x;
assert(scanf("%d", &x) == 1);
return x;
}
int main() {
int n, u, v;
n = read_int();
initialize(n);
for (int i = 0; i < n * (n - 1) / 2; i++) {
u = read_int();
v = read_int();
printf("%d\n", hasEdge(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... |