Submission #39644

#TimeUsernameProblemLanguageResultExecution timeMemory
39644funcsrGame (IOI14_game)C++14
100 / 100
626 ms19604 KiB
#include "game.h" #include <vector> #include <iostream> #include <set> #include <queue> #include <algorithm> #include <cassert> using namespace std; typedef pair<int, int> P; #define rep(i, n) for (int i=0; i<(n); i++) int N; int G[1500][1500]; int U[1500], R[1500]; int find(int x) { if (U[x] == x) return x; return U[x] = find(U[x]); } void unite(int x, int y) { x = find(x), y = find(y); if (x == y) return; if (R[x] < R[y]) swap(x, y); U[y] = x; R[x] += R[y]; rep(i, N) if (i != x && i != y) { G[x][i] += G[y][i]; G[i][x] += G[i][y]; } } void initialize(int n) { N = n; rep(i, N) U[i] = i, R[i] = 1; } int hasEdge(int u, int v) { u = find(u), v = find(v); assert(u != v); G[u][v]++, G[v][u]++; if (G[u][v] == R[u]*R[v]) { unite(u, v); return 1; } else return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...