# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
529100 | 2022-02-22T06:24:27 Z | Gurban | Bitaro the Brave (JOI19_ho_t1) | C++17 | 0 ms | 0 KB |
#include "bits/stdc++.h" #include "game.h" using namespace std; using ll = long long; const int maxn=1505; int p[maxn],sz[maxn]; map<int,int>m[maxn]; void initialize(int n) { for(int i = 0;i < n;i++){ p[i] = i; sz[i] = 1; } } int ata(int x){ if(p[x] == x) return x; return p[x] = ata(p[x]); } int hasEdge(int u, int v) { u = ata(u); v = ata(v); if(u == v) exit(0); if((int)m[u].size() < (int)m[v].size()) swap(u,v); int now = 0; if(m[v].find(u) != m[v].end()) now = m[v][u]; if(now == sz[u] * sz[v] - 1){ for(auto j : m[v]){ m[u][j.first] += j.second; m[j.first].erase(v); m[j.first][u] += j.second; } m[v].clear(); m[u].erase(v); p[v] = u; sz[u] += sz[v]; sz[v] = 0; return 1; } m[u][v]++; m[v][u]++; return 0; }