Submission #1123136

#TimeUsernameProblemLanguageResultExecution timeMemory
1123136SalihSahinGame (IOI14_game)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h> #define pb push_back //#define int long long using namespace std; #include "game.h" int N; vector<int> par; int comp; struct DSU{ vector<int> arr; }; vector<DSU> dsuarr; vector<vector<int> > edge; int fnd(int a){ if(a == par[a]) return a; else return par[a] = fnd(par[a]); } void merge(int a, int b){ int olda = a, oldb = b; a = fnd(a), b = fnd(b); par[b] = a; for(auto itr: dsuarr[b].arr){ dsuarr[a].arr.pb(itr); } edge[olda][oldb] = edge[oldb][olda] = 1; } void initialize(int n) { N = n; edge.resize(n); for(int i = 0; i < n; i++){ edge[i].resize(n); edge[i][i] = -1; } dsuarr.resize(n); for(int i = 0; i < n; i++){ dsuarr[i].arr.pb(i); } par.resize(n); for(int i = 0; i < n; i++){ par[i] = i; } comp = n; } int hasEdge(int u, int v) { int uset = fnd(u), vset = fnd(v); if(comp <= 2){ int choices = 0; for(auto itr: dsuarr[uset].arr){ for(auto itr2: dsuarr[vset].arr){ if(edge[itr][itr2] == 0) choices++; } } if(choices == 1){ merge(u, v); comp--; return 1; } else{ edge[u][v] = edge[v][u] = -1; return 0; } } else{ merge(u, v); comp--; return 1; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...