Submission #587763

#TimeUsernameProblemLanguageResultExecution timeMemory
587763yutabiGame (IOI14_game)C++14
100 / 100
412 ms25184 KiB
#include "game.h" #include <bits/stdc++.h> using namespace std; int N; int par[1500]; int sz[1500]; int cnt[1500][1500]; int find_parent(int node) { if(par[node]==node) { return node; } return find_parent(par[node]); } void make_union(int node1,int node2) { node1=find_parent(node1); node2=find_parent(node2); if(sz[node1]<sz[node2]) { swap(node1,node2); } sz[node1]+=sz[node2]; par[node2]=node1; for(int i=0;i<N;i++) { cnt[node1][i]+=cnt[node2][i]; cnt[i][node1]+=cnt[i][node2]; } } void initialize(int n) { N=n; for(int i=0;i<N;i++) { par[i]=i; sz[i]=1; } } int hasEdge(int u, int v) { u=find_parent(u); v=find_parent(v); assert(u!=v); cnt[u][v]++; cnt[v][u]++; if(cnt[u][v]==sz[u]*sz[v]) { make_union(u,v); return 1; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...