Submission #38906

#TimeUsernameProblemLanguageResultExecution timeMemory
38906adamczh1Game (IOI14_game)C++14
15 / 100
0 ms10808 KiB
#include "game.h" #include <bits/stdc++.h> using namespace std; struct UnionFind { vector<int> data; vector<int> remaining; void init(int n) { data.assign(n, -1); remaining.assign(n, n-1); } bool unionSet(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; remaining[x] += remaining[y]; remaining[x] -= 2; } return x != y; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } } uf; int cnt; int saidyes=0; bool danger=0; int N; void initialize(int n) { uf.init(n); N=n; cnt=n*(n-1)/2; } int hasEdge(int u, int v) { if(cnt+saidyes==N-1){ danger=1; } if(danger){ return 1; } cnt--; if(!uf.findSet(u,v) && (uf.remaining[uf.root(u)]==1 || uf.remaining[uf.root(v)]==1)){ uf.unionSet(u,v); saidyes++; return 1; } if(!uf.findSet(u,v)){ uf.remaining[uf.root(u)]--; uf.remaining[uf.root(v)]--; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...