Submission #344816

#TimeUsernameProblemLanguageResultExecution timeMemory
34481679brueGame (IOI14_game)C++14
15 / 100
3 ms512 KiB
#include <bits/stdc++.h> #include "game.h" using namespace std; typedef long long ll; int n; int par[1502]; int cnt[1502]; int sum[1502]; int queryCount; int find(int x){ if(x==par[x]) return x; return par[x] = find(par[x]); } void merge(int x, int y){ sum[find(x)] -= y, sum[find(y)] -= x; x = find(x), y = find(y); cnt[x]--, cnt[y]--; par[x] = y; sum[y] += sum[x]; cnt[y] += cnt[x]; sum[x] = cnt[x] = 0; } void initialize(int N){ n = N; for(int i=0; i<n; i++) par[i] = i; for(int i=0; i<n; i++) cnt[i] = n-1, sum[i] = n*(n-1)/2 - i; } int hasEdge(int u, int v){ queryCount++; if(find(u)==find(v)) return true; cnt[find(u)]--, cnt[find(v)]--; sum[find(u)]-=v, sum[find(v)]-=u; u = find(u), v = find(v); while(cnt[u] == 1){ merge(u, sum[u]); u = find(u); } while(cnt[v] == 1){ merge(v, sum[v]); v = find(v); } return false; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...