제출 #129644

#제출 시각아이디문제언어결과실행 시간메모리
129644Sorting게임 (IOI14_game)C++14
100 / 100
554 ms27788 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1507; int n; int par[N]; vector<int> el[N]; bool e[N][N]; int con[N][N]; bool unite(int u, int v){ if(el[par[u]].size() < el[par[v]].size()){ swap(u, v); } int pr = par[v]; for(int x: el[pr]){ par[x] = par[u]; } for(int x: el[pr]){ el[par[u]].push_back(x); for(int i = 0; i < x; i++){ if(!e[i][x]){ con[par[x]][par[i]]++; con[par[i]][par[x]]++; } } for(int i = x + 1; i < n; i++){ if(!e[x][i]){ con[par[x]][par[i]]++; con[par[i]][par[x]]++; } } } return true; } void initialize(int _n){ n = _n; for(int i = 0; i < n; i++){ par[i] = i; el[i].push_back(i); } for(int i = 0; i < n; i++){ for(int j = i + 1; j < n; j++){ e[i][j] = false; con[i][j] = 1; con[j][i] = 1; } } } int hasEdge(int u, int v){ e[min(u, v)][max(u, v)] = 1; if(con[par[u]][par[v]] == 1){ unite(u, v); return 1; } con[par[u]][par[v]]--; con[par[v]][par[u]]--; return 0; } /*int main(){ int _n; cin >> _n; initialize(_n); while(true){ int u, v; cin >> u >> v; cout << hasEdge(u, v) << endl; } return 0; }*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...