제출 #1049362

#제출 시각아이디문제언어결과실행 시간메모리
1049362ArthuroWich게임 (IOI14_game)C++17
0 / 100
1 ms348 KiB
#include "game.h" #include<bits/stdc++.h> using namespace std; int p[1505]; set<pair<int, int>> st[1505]; int find(int x) { if (p[x] == x) { return x; } p[x] = find(p[x]); return p[x]; } void merge(int a, int b) { a = find(a); b = find(b); if (a == b) { return; } p[b] = a; } void initialize(int n) { for (int i = 0; i < n; i++) { p[i] = i; } for (int i = 0; i < n; i++) { for (int j = i+1; j < n; j++) { st[i].insert({i, j}); st[j].insert({i, j}); } } } int hasEdge(int u, int v) { int a = u, b = v; u = min(a, b); v = max(a, b); set<pair<int, int>> todel; for (auto [p, q] : st[u]) { if (find(p) == find(q)) { todel.insert({p, q}); } } for (auto p : todel) { st[u].erase(p); } todel.clear(); for (auto [p, q] : st[v]) { if (find(p) == find(q)) { todel.insert({p, q}); } } for (auto p : todel) { st[v].erase(p); } if (st[u].empty() || st[v].empty() || find(u) == find(v)) { return 0; } if (st[u].size() < 2) { st[u].erase({u, v}); st[v].erase({u, v}); merge(u, v); return 1; } st[u].erase({u, v}); st[v].erase({u, v}); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...