제출 #777755

#제출 시각아이디문제언어결과실행 시간메모리
777755canadavid1게임 (IOI14_game)C++14
42 / 100
1076 ms2504 KiB
#include "game.h" #include <bits/stdc++.h> using namespace std; vector<int> sz; vector<int> pp; vector<int> sz2; vector<int> pp2; vector<pair<int,int>> edge; int find(int id, vector<int>& pp) { if(pp[id] != id) { pp[id] = find(pp[id],pp); } return pp[id]; } bool unite(int a,int b,vector<int>& sz, vector<int>& pp) { if(a==b) return false; a = find(a,pp); b = find(b,pp); 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); sz2 = sz; pp2 = pp; *find(edge.begin(),edge.end(),pair<int,int>{u,v}) = {0,0}; for(auto i : edge) unite(i.first,i.second,sz2,pp2); if(find(u,pp2)==find(v,pp2)) return 0; unite(u,v,sz,pp); return 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...