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>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
using namespace std;
#define sp " "
#define endl "\n"
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt","w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define LL node * 2
#define RR node * 2
#define mid (l + r) / 2
#define ll long long
#define MAXN 1600
const int modulo = 1e9 + 7;
const ll INF = 2e18 +7;
int N;
bitset<MAXN> adj[MAXN];
set<int> child[MAXN];
int par[MAXN], tin[MAXN], tout[MAXN], cntr, sz[MAXN];
void initialize(int n) {
N = n;
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++) adj[i].set(j, 1);
}
for (int i = 1; i < n; i++){
child[0].insert(i);
child[i].insert(0);
par[i] = 0;
}
par[0] = -1;
}
void dfs(int node, int root){
// cout<<node<<sp<<root<<endl;
par[node] = root;
tin[node] = ++cntr;
sz[node] = 1;
for (auto i : child[node]){
if (i == root) continue;
dfs(i, node);
sz[node] += sz[i];
}
tout[node] = cntr;
}
void sub(int node, int root, bitset<MAXN> &b){
b |= adj[node];
for (auto i : child[node]){
if (i == root) continue;
sub(i, node, b);
}
}
int hasEdge(int u, int v) {
cntr = 0;
dfs(v, -1);
adj[u].set(v, 0);
adj[v].set(u, 0);
if (par[u] != v){
return 0;
}
child[u].erase(v);
child[v].erase(u);
bitset<MAXN> to;
to.reset();
sub(u, v, to);
int parr = -1;
for (int i = 0; i < N; i++){
if (tin[i] >= tin[u] && tout[i] <= tout[u]) continue;
if (to[i] == 1){
parr = i;
break;
}
}
if (parr == -1){
adj[u][v] = 1;
adj[v][u] = 1;
child[u].insert(v);
child[v].insert(u);
return 1;
}
int c = -1;
for (int i = 0; i < N; i++){
if (tin[i] >= tin[u] && tout[i] <= tout[u] && adj[i][parr] == 1){
c = i;
break;
}
}
child[parr].insert(c);
child[c].insert(parr);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |