Submission #558572

#TimeUsernameProblemLanguageResultExecution timeMemory
558572urosk게임 (IOI14_game)C++14
100 / 100
416 ms25296 KiB
#include "game.h"
// __builtin_popcount(x)
// __builtin_popcountll(x)
#define here cerr<<"===========================================\n"
#include <bits/stdc++.h>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
using namespace std;
#define maxn 1505
int n;
ll dsu[maxn];
bitset<maxn> f[maxn];
ll d[maxn][maxn];
ll siz[maxn];
ll root(ll x){
    while(x!=dsu[x]){
        dsu[x] = dsu[dsu[x]];
        x = dsu[x];
    }
    return x;
}
ll comp = n;
void upd(ll x,ll y){
    x = root(x);
    y = root(y);
    if(x==y) return;
    d[x][y]++;
    d[y][x]++;
    if(d[x][y]==siz[x]*siz[y]){
        comp--;
        dsu[y] = x;
        siz[x]+=siz[y];
        for(ll i = 1;i<=n;i++) d[x][i]+=d[y][i];
        for(ll i = 1;i<=n;i++) d[i][x]+=d[y][i];
    }
}
void initialize(int N) {
    n = N;
    for(ll i = 1;i<=n;i++) for(ll j = 1;j<=n;j++) d[i][j] = 0;
    iota(dsu+1,dsu+n+1,1);
    fill(siz,siz+n+1,1);
    comp = n;
}
bitset<maxn> pito[maxn];
int hasEdge(int u, int v) {
    u++;
    v++;
    ll complast = comp;
    upd(u,v);
    //cerr<<"upit: "<<u<< " "<<v<<endl;
    //cerr<<ru<< " "<<siz[ru]<<" "<<d[ru][rv]<<endl;
    //cerr<<rv<< " "<<siz[rv]<<" "<<d[rv][ru]<<endl;
    bool ima = 0;
    if(comp!=complast) ima = 1;
    return ima;
}
/*
4
0 1
3 0
1 2
0 2
3 1
2 3
4
0 3
1 0
0 2
3 1
1 2
2 3
4
0 3
1 0
0 2
3 1
1 2
2 3
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...