This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3")
#pragma GCC target("avx,sse,sse2,avx2")
#include "game.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
struct dsu {
vi r, p, d;
vi cnt[1500];
void init(int n) {
r.resize(n+1);
p.resize(n+1);
d.resize(n+1, 0);
for(int i = 0; i <= n; i++) p[i] = i, cnt[i].resize(n+1, 0);
}
int par(int i) {
if(i == p[i]) return i;
return p[i] = par(p[i]);
}
void unite(int u, int v) {
u=par(u),v=par(v);
if(u==v) return;
if(r[u]<r[v]) swap(u, v);
p[v] = u;
r[u] += r[u]==r[v];
for(int i =0;i<r.size();i++)
cnt[u][i] += cnt[v][i];
d[v]=true;
}
};
#define left afsjlk
dsu x;
set<pair<int, int>> left;
int n;
void initialize(int N) {
n=N;
x.init(n);
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
x.cnt[i][j]++;
}
void upd(int v) {
for(int i = 0; i < n; i++) {
if(x.d[i]) continue;
ll z = x.cnt[i][v];
x.cnt[i][v] = 0;
x.cnt[i][x.par(v)]+=z;
}
}
int hasEdge(int u, int v) {
if(u>v)swap(u, v);
if((u=x.par(u))==(v=x.par(v)))
return 1;
//cout << x.cnt[u][v] << '\n';
int t = x.cnt[u][v];x.cnt[u][v]--, x.cnt[v][u]--;
if(t==1) x.unite(u, v), upd(u), upd(v);
return t==1;
}
//int main(){
//}
Compilation message (stderr)
game.cpp: In member function 'void dsu::unite(int, int)':
game.cpp:27:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i =0;i<r.size();i++)
~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |