#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int MAXN = 1510;
int N;
int e[MAXN][MAXN];
bool f[MAXN][MAXN];
void initialize(int n){
memset(e, -1, sizeof(e)); N = n;
memset(f, 1, sizeof(f));
}
void set_edge(int x, int y, bool val){
e[x][y] = val, e[y][x] = val;
f[x][y] = val, f[y][x] = val;
}
bool bio[MAXN];
bool bad(){
int cnt = 0;
memset(bio, 0, sizeof(bio));
for (int i = 0; i < N; ++i){
if (bio[i])
continue;
++cnt; bio[i] = 1;
queue<int> q; q.push(i);
while (!q.empty()){
int x = q.front(); q.pop();
for (int y = 0; y < N; ++y){
if (!f[x][y] || bio[y]) continue;
bio[y] = 1, q.push(y);
}
}
}
//cout << "! " << cnt << endl;
return (cnt > 1);
}
int hasEdge(int x, int y){
set_edge(x, y, 0);
if (bad()) set_edge(x, y, 1);
//cout << x << ' ' << y << " -> " << e[x][y] << endl;
return e[x][y];
}
/*int main(){
int n; cin >> n;
initialize(n);
int m = n * (n - 1) / 2;
while (m--){
int x, y; cin >> x >> y;
cout << hasEdge(x, y) << '\n';
}
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... |