제출 #300563

#제출 시각아이디문제언어결과실행 시간메모리
300563anonymous게임 (IOI14_game)C++14
0 / 100
1 ms512 KiB
#include "game.h" #include <iostream> #define MAXN 1505 using namespace std; int Cmp, N, adj[MAXN][MAXN]; class DSU { public: int Set[MAXN]; void init(int n) { for (int i=0; i<=n; i++) {Set[i] = i;} } int Find(int x) { return(Set[x] == x ? x : Set[x] = Find(Set[x])); } void Union(int x, int y) { int p1 = Find(x), p2 = Find(y); Set[p1] = p2; for (int i=0; i<N; i++) { if (Find(i) != x && i == Find(i)) { adj[i][y] += adj[i][x]; adj[y][i] += adj[i][x]; } } } } UF; void initialize(int n) { UF.init(n), N=n; Cmp = N; for (int i=0; i<N; i++) { for (int j=i+1; j<N; j++) { adj[i][j]=adj[j][i] = 1; } } } int hasEdge(int u, int v) { int p1 = UF.Find(u), p2 = UF.Find(v); if (p1 == p2) {return(1);} adj[p1][p2]--, adj[p2][p1]--; if (adj[p1][p2]) { return(0); } UF.Union(u,v); return(1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...