제출 #777764

#제출 시각아이디문제언어결과실행 시간메모리
777764canadavid1게임 (IOI14_game)C++14
42 / 100
1077 ms2504 KiB
#include "game.h" #include <bits/stdc++.h> using namespace std; vector<int> sz; vector<int> pp; vector<pair<int,int>> edge; int find(int id) { if(pp[id] != id) { pp[id] = find(pp[id]); } return pp[id]; } bool unite(int a,int b) { if(a==b) return false; a = find(a); b = find(b); if (a==b) return false; if(sz[a] < sz[b]) swap(a,b); pp[b] = a; sz[a] += sz[b]; return true; } void initialize(int n) { for(int i = 0; i < n; i++) for(int j = 0; j < i; j++) edge.push_back({j,i}); pp.resize(n); iota(pp.begin(),pp.end(),0); sz.assign(n,1); } int hasEdge(int u, int v) { if (u > v) swap(u,v); sz.assign(sz.size(),1); iota(pp.begin(),pp.end(),0); *find(edge.begin(),edge.end(),pair<int,int>{u,v}) = {0,0}; for(auto i : edge) unite(i.first,i.second); if(find(u)==find(v)) return 0; *find(edge.begin(),edge.end(),pair<int,int>{0,0}) = {u,v}; unite(u,v); return 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...