Submission #1006608

#TimeUsernameProblemLanguageResultExecution timeMemory
1006608The_SamuraiGame (IOI14_game)C++17
100 / 100
214 ms18016 KiB
#include "game.h" #include "bits/stdc++.h" using namespace std; const int N = 1500; int n; vector<int> p(N); vector<vector<int>> comp(N), ways(N, vector(N, 0)); void initialize(int _n) { n = _n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i != j) ways[i][j]++; } p[i] = i; comp[i].emplace_back(i); } } void merge(int u, int v) { u = p[u], v = p[v]; assert(u != v); if (comp[u].size() < comp[v].size()) swap(u, v); for (int x: comp[v]) { p[x] = u; comp[u].emplace_back(x); } comp[v].clear(); for (int i = 0; i < n; i++) { ways[u][i] += ways[v][i]; ways[i][u] += ways[v][i]; } } int hasEdge(int u, int v) { if (p[u] == p[v]) return 0; if (ways[p[u]][p[v]] > 1) { ways[p[u]][p[v]]--; ways[p[v]][p[u]]--; return 0; } merge(u, v); return 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...