Submission #961149

#TimeUsernameProblemLanguageResultExecution timeMemory
961149Nahian9696Game (IOI14_game)C++17
100 / 100
288 ms31648 KiB
#include "game.h" #include <algorithm> int n, num_comps; int par[2000]; int comp_size[2000]; int comp_edges[2000][2000]; int find(int u) { if (par[u] == u) { return u; } return par[u] = find(par[u]); } void initialize(int nn) { n = nn; for (int i = 0; i < n; i++) { par[i] = i; comp_size[i] = 1; for(int j = 0; j < n; j++) { comp_edges[i][j] = 0; } } num_comps = n; } int hasEdge(int u, int v) { // if (find(u) == find(v)) { // return 1; // } u = find(u); v = find(v); if(comp_edges[u][v] + 1 == comp_size[u] * comp_size[v]) { comp_edges[u][v] = 0; comp_edges[v][u] = 0; for(int i = 0; i < n; i++) { comp_edges[u][i] += comp_edges[v][i]; comp_edges[v][i] = 0; comp_edges[i][u] += comp_edges[i][v]; comp_edges[i][v] = 0; } comp_size[u] += comp_size[v]; comp_size[v] = 0; par[v] = u; return 1; } else { comp_edges[u][v]++; comp_edges[v][u]++; return 0; } // if(num_comps > 2) { // if(find(u) < find(v)) { // std::swap(u, v); // } // par[find(u)] = find(v); // num_comps--; // return 1; // } else { // return 0; // } return 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...