Submission #67500

#TimeUsernameProblemLanguageResultExecution timeMemory
67500VahanGame (IOI14_game)C++17
100 / 100
838 ms39244 KiB
#include "game.h" #include<iostream> using namespace std; int s[1600],p[1600],n,g[1600][1600]; void setcreate(int a) { s[a]=1; p[a]=a; } int setparent(int a) { if(a==p[a]) return a; p[a]=setparent(p[a]); return p[a]; } void setunion(int a,int b) { a=setparent(a); b=setparent(b); if(a==b) return; if(s[a]>=s[b]) { s[a]+=s[b]; p[b]=a; for(int i=0;i<n;i++) { g[a][i]+=g[b][i]; g[i][a]=g[a][i]; } } else { s[b]+=s[a]; p[a]=b; for(int i=0;i<n;i++) { g[b][i]+=g[a][i]; g[i][b]=g[b][i]; } } } void initialize(int N) { n=N; for(int i=0;i<n;i++) setcreate(i); } int hasEdge(int u, int v) { int a=setparent(u); int b=setparent(v); if(g[a][b]+1==s[b]*s[a]) { setunion(a,b); return 1; } else { g[a][b]++; g[b][a]++; return 0; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...