Submission #1062937

#TimeUsernameProblemLanguageResultExecution timeMemory
1062937damjandavkovGame (IOI14_game)C++17
100 / 100
271 ms25288 KiB
#include "game.h" #include <bits/stdc++.h> using namespace std; vector<vector<int> > v; vector<int> pa, sz; int N; int fin(int i) { if (pa[i] == i) return i; pa[i] = fin(pa[i]); return pa[i]; } void mer(int a, int b) { a = fin(a); b = fin(b); if (sz[a] > sz[b]) swap(a, b); pa[a] = b; sz[b] += sz[a]; for (int i = 0; i < N; i++) { if (pa[i] != i || i == a || i == b) continue; v[i][b] += v[i][a]; v[b][i] += v[a][i]; } } void initialize(int n) { int i, j; N = n; pa.resize(n); sz.resize(n); v.resize(n); for (i = 0; i < n; i++) { pa[i] = i; sz[i] = 1; v[i].resize(n); for (j = 0; j < n; j++) v[i][j] = 1; } } int hasEdge(int a, int b) { a = fin(a); b = fin(b); if (v[a][b] > 1) { v[a][b]--; v[b][a]--; return 0; } mer(a, b); return 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...