This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1.5e3 + 5;
int N;
int g[maxn][maxn];
int vis[maxn];
void delete_edge(int u, int v) {
g[u][v] = g[v][u] = 0;
}
void add_edge(int u, int v) {
g[u][v] = g[v][u] = 1;
}
void dfs(int u, int &cnt) {
vis[u] = 1;
cnt++;
for(int i = 0; i < N; i++) {
if(g[u][i] and !vis[i]) {
dfs(i, cnt);
}
}
}
bool connected() {
for(int i = 0; i < N; i++) {
vis[i] = 0;
}
int cnt = 0;
dfs(0, cnt);
return cnt != N ? 0 : 1;
}
void initialize(int n) {
N = n;
for(int i = 0; i < N; i++) {
for(int j = 0; j < N; j++) {
g[i][j] = 1;
}
}
}
int hasEdge(int u, int v) {
delete_edge(u, v);
if(connected()) {
return 0;
} else {
add_edge(u, v);
return 1;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |