Submission #581343

#TimeUsernameProblemLanguageResultExecution timeMemory
581343kamelfanger83Game (IOI14_game)C++14
100 / 100
467 ms25232 KiB
#include <iostream> #include <vector> #include "game.h" using namespace std; vector<int> group; vector<vector<int>> cons; int gn; int get(int u){ int s = u; while(u != group[u]) u = group[u]; while(s != group[s]){ int ls = s; s = group[s]; group[ls] = u; } return u; } void unite(int u, int v){ u = get(u); v = get(v); for(int adder = 0; adder < gn; ++adder) cons[u][adder] += cons[v][adder]; for(int oc = 0; oc < gn; ++oc) cons[oc][u] += cons[oc][v]; group[v] = u; } void initialize(int n){ group.resize(n); for(int i = 0; i < n; ++i) group[i] = i; cons.assign(n, vector<int> (n, 1)); for(int i = 0; i < n; ++i) cons[i][i] = 0; gn = n; } int hasEdge(int u, int v){ if(cons[get(u)][get(v)] != 1){ cons[get(u)][get(v)] -= 1; cons[get(v)][get(u)] -= 1; return 0; } else{ unite(u, v); return 1; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...