제출 #366793

#제출 시각아이디문제언어결과실행 시간메모리
366793KoD게임 (IOI14_game)C++17
100 / 100
507 ms28368 KiB
#include <bits/stdc++.h> struct DSU { std::vector<int> par; DSU() { } DSU(const int n): par(n, -1) { } int find(const int u) { return par[u] < 0 ? u : par[u] = find(par[u]); } void absorb(int u, int v) { u = find(u); v = find(v); if (u == v) { return; } par[v] = u; } }; DSU dsu; int N; int count[2000][2000]; void initialize(int n) { N = n; dsu = DSU(n); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (i != j) { count[i][j] = 1; } } } } int hasEdge(int u, int v) { u = dsu.find(u); v = dsu.find(v); if (count[u][v] == 1) { for (int i = 0; i < N; ++i) { count[u][i] += count[v][i]; count[i][u] += count[v][i]; } dsu.absorb(u, v); return 1; } else { count[u][v] -= 1; count[v][u] -= 1; return 0; } } #ifdef __APPLE__ int main() { int n; std::cin >> n; initialize(n); for (int i = 0; i < n; ++i) { for (int j = 0; j < i; ++j) { int u, v; std::cin >> u >> v; std::cout << hasEdge(u, v) << '\n'; } } } #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...