Submission #516547

#TimeUsernameProblemLanguageResultExecution timeMemory
516547tjd229Game (IOI14_game)C++14
15 / 100
1 ms332 KiB
#include "game.h" int n,tot,e; int rem[1500]; int p[1500]; int find(int a) { if (p[a] != a) p[a] = find(p[a]); return p[a]; } bool dsu(int a, int b) { a = find(a); b = find(b); if (a == b) return false; p[b] = a; rem[a] += rem[b]; return true; } void initialize(int n) { ::n = n; for (int i = 0; i < n; ++i) rem[i] = n - 1,p[i]=i; tot = n * (n - 1) / 2; e = n - 1; } int hasEdge(int u, int v) { if (e == 1 && tot > 1) { --tot; return 0; } if (e == tot) { --e; --tot; return 1; } int U = find(u), V = find(v); --tot; if (V==U) { rem[U] -= 2; return 0; } --rem[U]; --rem[V]; if (rem[U] == 1 || rem[V] == 1) { dsu(U, V); --e; return 1; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...