Submission #1049470

#TimeUsernameProblemLanguageResultExecution timeMemory
1049470ArthuroWichGame (IOI14_game)C++17
42 / 100
1042 ms111944 KiB
#include "game.h" #include<bits/stdc++.h> using namespace std; int p[1505]; set<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; } int h = -1, co = 0; void initialize(int n) { h = -1; co = 0; 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(j); st[j].insert(i); } } } int hasEdge(int u, int v) { if (co == 0) { h = u; merge(u, v); co++; return 1; } if (find(u) == find(v)) { return 0; } if (find(u) == find(h)) { int co = 0; for (int x : st[v]) { if (find(x) == find(h)) { co++; } } st[v].erase(u); if (co == 1) { merge(h, v); return 1; } else { return 0; } } else if (find(v) == find(h)) { int co = 0; for (int x : st[u]) { if (find(x) == find(h)) { co++; } } st[u].erase(v); if (co == 1) { merge(h, u); return 1; } else { return 0; } } else { st[v].erase(u); st[u].erase(v); return 0; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...