제출 #968529

#제출 시각아이디문제언어결과실행 시간메모리
968529Hugo1729게임 (IOI14_game)C++11
100 / 100
343 ms27224 KiB
#include <bits/stdc++.h> #include "game.h" using namespace std; int n; vector<int> e; vector<vector<int>> val; int find(int v){ if(e[v]<0)return v; else{ e[v]=find(e[v]); return e[v]; } } bool same(int x, int y){ return (find(x)==find(y)); } int sz(int v){ return -e[find(v)]; } void connect(int x, int y){ x=find(x); y=find(y); if(x==y)return; if(e[x]>e[y])swap(x,y); for(int i=0;i<n;i++){ if(find(i)==i){ int sus=val[y][i]; val[y][i]-=sus; val[i][y]-=sus; val[x][i]+=sus; val[i][x]+=sus; } } e[x]+=e[y]; e[y]=x; } void initialize(int s) { n=s; e.assign(n,-1); val.assign(n,vector<int>(n,0)); } int hasEdge(int u, int v) { u=find(u);v=find(v); if(u==v)return 1; // cout << v << ' ' << u << ' ' << sz(v)*sz(u) << ' ' << val[v][u] << ' ' << val[u][v] << '\n'; if(sz(v)*sz(u)==val[v][u]+1){ connect(v,u); return 1; }else{ val[v][u]++; val[u][v]++; return 0; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...