제출 #784392

#제출 시각아이디문제언어결과실행 시간메모리
784392qwerasdfzxcl게임 (IOI14_game)C++17
100 / 100
290 ms24464 KiB
#include "game.h" #include <bits/stdc++.h> typedef long long ll; using namespace std; int n; struct DSU{ int path[1515], cnt[1515][1515]; void init(int n){ for (int i=1;i<=n;i++){ path[i] = i; for (int j=1;j<=n;j++) if (i!=j) cnt[i][j] = 1; } } int find(int s){ if (s==path[s]) return s; return path[s] = find(path[s]); } int merge(int s, int v){ s = find(s), v = find(v); assert(s!=v); if (cnt[s][v] > 1){ cnt[s][v]--; cnt[v][s]--; return 0; } path[v] = s; for (int i=1;i<=n;i++) if (find(i)==i && i!=s){ cnt[s][i] += cnt[v][i]; cnt[i][s] = cnt[s][i]; } return 1; } }dsu; void initialize(int N) { n = N; dsu.init(n); } int hasEdge(int u, int v) { ++u, ++v; return dsu.merge(u, v); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...