제출 #67488

#제출 시각아이디문제언어결과실행 시간메모리
67488Vahan게임 (IOI14_game)C++17
15 / 100
4 ms1040 KiB
#include "game.h" 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[a][i]+=g[b][i]; g[i][a]=g[a][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...