Submission #730331

#TimeUsernameProblemLanguageResultExecution timeMemory
730331sofija6Game (IOI14_game)C++14
100 / 100
346 ms25220 KiB
#include <bits/stdc++.h> #define MAXN 1510 using namespace std; int cnt[MAXN][MAXN],d[MAXN],N; int Root(int p) { while (d[p]!=p) { d[p]=d[d[p]]; p=d[p]; } return p; } void Join(int u,int v) { int ru=Root(u),rv=Root(v); if (rv<ru) swap(ru,rv); d[rv]=ru; for (int i=0;i<N;i++) { cnt[ru][i]+=cnt[rv][i]; cnt[i][ru]+=cnt[rv][i]; } } void initialize(int n) { N=n; for (int i=0;i<n;i++) { for (int j=0;j<n;j++) cnt[i][j]=1; d[i]=i; } } int hasEdge(int u, int v) { int ru=Root(u),rv=Root(v); if (ru!=rv && cnt[ru][rv]==1) { Join(ru,rv); return 1; } cnt[ru][rv]--; cnt[rv][ru]--; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...