Submission #197492

#TimeUsernameProblemLanguageResultExecution timeMemory
197492handlenameGame (IOI14_game)C++17
100 / 100
481 ms25172 KiB
#include <bits/stdc++.h> #include "game.h" using namespace std; int parent[1501]; int countt[1501][1501]; int sizee[1501]; int N; int root(int x) { if (parent[x]==x) return x; return parent[x] = root(parent[x]); } bool isConnected(int x, int y) { return root(x) == root(y); } void connect(int x, int y) { int rootX = root(x); int rootY = root(y); if(rootX != rootY){ parent[rootX] = rootY; sizee[rootY] += sizee[rootX]; for (int i=0;i<N;i++){ if (root(i)==i && i!=rootY){ countt[rootY][i]+=countt[rootX][i]; countt[i][rootY]+=countt[i][rootX]; } } } } void initialize(int n){ for (int i=0;i<n;i++) { parent[i]=i; sizee[i]=1; } N=n; } int hasEdge(int u, int v){ int rootu=root(u),rootv=root(v); if (countt[rootu][rootv]==sizee[rootu]*sizee[rootv]-1){ connect(u,v); return 1; } countt[rootu][rootv]++; countt[rootv][rootu]++; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...