Submission #207139

#TimeUsernameProblemLanguageResultExecution timeMemory
207139aloo123Game (IOI14_game)C++14
0 / 100
5 ms376 KiB
#include <bits/stdc++.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)){ return 0; } if(findpar(v) == findpar(a)){ 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; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...