#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1500;
int n, sum, deg[N], cnt[N];
unordered_set<int> vis, adj[N];
void dfs(int x) {
vis.insert(x);
sum++;
for (int y : adj[x]) {
if (vis.find(y) != vis.end()) continue;
dfs(y);
}
}
void initialize(int NN) {
n = NN;
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i < n; i++) {
deg[i] = n;
cnt[n]++;
}
for (int i = 0; i < n; i++) {
for (int j = i+1; j < n; j++) {
adj[i].insert(j);
adj[j].insert(i);
}
}
}
int hasEdge(int u, int v) {
adj[u].erase(v);
adj[v].erase(u);
deg[u]--;
deg[v]--;
cnt[deg[u]]++;
cnt[deg[v]]++;
if (cnt[deg[u]] == deg[u]) {
vis.clear();
sum = 0;
dfs(u);
if (sum < n) {
cnt[deg[u]]--;
cnt[deg[v]]--;
deg[u]++;
deg[v]++;
adj[u].insert(v);
adj[v].insert(u);
return 1;
}
}
if (cnt[deg[v]] == deg[v]) {
vis.clear();
sum = 0;
dfs(v);
if (sum < n) {
cnt[deg[u]]--;
cnt[deg[v]]--;
deg[u]++;
deg[v]++;
adj[u].insert(v);
adj[v].insert(u);
return 1;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |