#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 1500;
vector<pair<int,int>> adj[N];
bool removed[N*N], vis[N];
void initialize(int n) {
int ind = 0;
for (int v = 0; v < n; v++) {
for (int u = 0; u < v; u++, ind++) {
adj[u].emplace_back(v, ind);
adj[v].emplace_back(u, ind);
}
}
}
bool dfs(int s, int t) {
if (s == t) return true;
vis[s] = true;
for (auto [nx, ind] : adj[s]) {
if (removed[ind] || vis[nx]) continue;
if (dfs(nx, t)) return true;
}
return false;
}
int hasEdge(int u, int v) {
for (auto [v_, ind] : adj[u]) {
if (v == v_) {
removed[ind] = true;
}
}
fill(vis, vis + N, false);
return !dfs(u, v);
}