이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "game.h"
#include <bits/stdc++.h>
#define lb lower_bound
#define LINE "------------\n"
using namespace std;
using PII = pair <int, int>;
const int N = 1500;
set <int> children[N];
set <PII> connections;
int connected[N];
void initialize(int n) {
for (int i = 0; i < n; i++)
for (int j = i+1; j < n; j++) {
children[i].insert(j);
children[j].insert(i);
}
for (int i = 1; i < n; i++) {
connected[i]++, connected[i-1]++;
connections.insert({i-1, i});
}
}
int hasEdge(int u, int v) {
// cout << LINE;
if (u > v) swap(u, v);
if (!connections.count({u, v})) {
// cout << "HERE1\n";
children[u].erase(v);
children[v].erase(u);
return 0;
}
bool fixed = 0;
// cout << u << " " << children[u].size() << ' ' << connected[u] << '\n';
if (children[u].size() - connected[u] > 0) {
// cout << "OPEN\n";
for (auto el : children[u]) {
int x = el, y = u;
if (x > y) swap(x, y);
if (connections.count({x, y})) continue;
connections.erase(connections.lb({u, v}));
connections.insert({x, y});
children[u].erase(v);
children[v].erase(u);
connected[u]--, connected[v]--;
connected[x]++, connected[y]++;
fixed = 1;
break;
}
}
return !fixed;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |