Submission #382323

#TimeUsernameProblemLanguageResultExecution timeMemory
382323davooddkareshkiGame (IOI14_game)C++17
15 / 100
2 ms512 KiB
//#include "game.h" #include<bits/stdc++.h> typedef long long ll; typedef long double ld; using namespace std; //#define int long long #define F first #define S second #define pii pair<int,int> #define mpr make_pair const int inf = 1e9; const int maxn = 1510; const int mod = 1e9+7; int n; int pors[maxn][maxn], par[maxn], sz[maxn]; int get_par(int v) { if(par[v] == -1) return v; return (par[v] = get_par(par[v])); } bool ans; void dsu(int u, int v) { u = get_par(u); v = get_par(v); if(sz[v] < sz[u]) swap(u,v); ans = 0; pors[u][v]++; pors[v][u]++; if(pors[u][v] == (sz[v] * sz[u])) { for(int i = 1; i <= n; i++) { if(par[i] == -1 && i != u && i != v) { pors[v][i] += pors[u][i]; pors[i][v] += pors[u][i]; } } ans = 1; sz[v] += sz[u]; par[u] = v; } } void initialize(int N) { n = N; memset(par, -1, sizeof par); fill(sz, sz+maxn, 1); } int hasEdge(int u, int v) { dsu(u,v); return ans; } /* signed main() { //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); initialize(6); cout<< hasEdge(0,3) <<"\n"; cout<< hasEdge(2,0) <<"\n"; cout<< hasEdge(0,1) <<"\n"; cout<< hasEdge(1,2) <<"\n"; cout<< hasEdge(1,3) <<"\n"; cout<< hasEdge(2,3) <<"\n"; } */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...