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 <bits/stdc++.h>
#include "game.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define lb lower_bound
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
vector<int> par; int N; set<ii> E;
int findSet(int v, vector<int>& p) {
if(p[v] == v) return v;
return p[v] = findSet(p[v], p);
}
bool sameSet(int u, int v, vector<int>& p) {
return findSet(u, p) == findSet(v, p);
}
void unionSet(int u, int v, vector<int>& p) {
u = findSet(u, p), v = findSet(v, p);
if(u == v) return;
p[u] = v;
}
void initialize(int n) {
N = n; par.resize(n);
for(int l = 0; l < n; l++) {
par[l] = l;
for(int i = l + 1; i < n; i++)
E.insert({l, i});
}
}
int hasEdge(int u, int v) {
if(u > v) swap(u, v);
vector<int> p(N);
for(int l = 0; l < N; l++) p[l] = par[l];
E.erase({u, v});
for(auto e : E) {
if(e.ff == u && e.ss == v) continue;
unionSet(e.ff, e.ss, p);
}
bool ok =1;
for(int l = 1; l < N; l++)
ok &= (sameSet(l, l - 1, p));
if(ok) return 0;
unionSet(u, v, par);
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... |