# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
207126 | aloo123 | Game (IOI14_game) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <wall.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
using namespace std;
const ll N = 2e6+5;
const ll MOD = 1e9+7;
ll sz[1505];
ll par[1505];
ll cc;
bool fl = false;
ll a=-1,b=-1;
void make_set(ll nd){
sz[nd] = 1;
par[nd] = nd;
}
ll findpar(ll nd){
if(par[nd] == nd) return nd;
else return par[nd] = findpar(par[nd]);
}
void merge(ll u,ll v){
u = findpar(u),v = findpar(v);
if(u == v) return ;
if(sz[u] > sz[v]) swap(u,v);
sz[v] += sz[u];
par[u] = v;
cc--;
}
void initialize(int n){
for(int i = 1;i<=n;i++) make_set(i);
cc =n;
}
int hasEdge(int u, int v){
++u,++v;
if(fl == false) {
fl = true;
merge(u,v);
a = u;
return 1;
}
if(findpar(u) == findpar(v)){
return 1;
}
if(b == -1){
if(findpar(u) == findpar(a)){
b = v;
return 0;
}
if(findpar(v) == findpar(a)){
b = u;
return 0;
}
b= u;
merge(u,v);
return 1;
}
else{
if(findpar(u) == findpar(a) || findpar(a) == findpar(v)){
merge(u,v);
return 1;
}
if(findpar(u) == findpar(b) || findpar(b) == findpar(v)){
merge(u,v);
return 1;
}
return 0;
}
}