이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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];
ll siz[maxn];
ll root(ll x){
while(x!=dsu[x]){
dsu[x] = dsu[dsu[x]];
x = dsu[x];
}
return x;
}
void upd(ll x,ll y){
x = root(x);
y = root(y);
if(x==y) return;
dsu[x] = y;
siz[y]+=siz[x];
}
ll d[maxn][maxn];
void initialize(int N) {
n = N;
for(ll i = 1;i<=n;i++) for(ll j = 1;j<=n;j++) d[i][j] = -1;
iota(dsu+1,dsu+n+1,1);
fill(siz,siz+n+1,1);
}
bitset<maxn> pito[maxn];
int hasEdge(int u, int v) {
u++;
v++;
ll ru = root(u);
ll rv = root(v);
vector<ll> a;
vector<ll> b;
for(ll i = 1;i<=n;i++){
if(root(i)==ru) a.pb(i);
if(root(i)==rv) b.pb(i);
}
ll ima = 1;
/*
here;
cerr<<"upit: "<<u<<" "<<v<<endl;
for(ll x : a) cerr<<x<< " ";
cerr<<endl;
for(ll x : b) cerr<<x<< " ";
cerr<<endl;
*/
bitset<maxn> c;
for(ll x : b) c[x] = 1;
for(ll x : a){
if(x==u) c[v] = 0;
if((c&pito[x])!=c) ima = 0;
if(x==u) c[v] = 1;
}
d[u][v] = d[v][u] = ima;
pito[u][v] = 1;
pito[v][u] = 1;
if(ima) upd(u,v);
//cerr<<"ima: "<<ima<<endl;
//here;
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |