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;
vector< vector< int > > Graph;
vector< bool > visited;
int n_;
bool cycle(int node, int last){
visited[node] =true;
for(int i = 0; i < n_; i++){
if(Graph[node][i] && !visited[i]){
if(cycle(i,node)) return true;
}else if(Graph[node][i] && visited[i] && i != last) return true;
}
return false;
}
void initialize(int n) {
n_ = n;
Graph.resize(n, vector<int>(n, false));
visited.resize(n);
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(i == j) continue;
Graph[i][j] = true;
Graph[j][i] = true;
}
}
}
int hasEdge(int u, int v) {
Graph[u][v] = false;
Graph[v][u] = false;
fill(visited.begin(), visited.end(), false);
bool verif = true;
for(int i = 0; i < n_; i++){
if(!visited[i]) verif = false;
}
if(cycle(u,-1) && verif){
return 0;
}else{
Graph[u][v] = true;
Graph[v][u] = true;
return 1;
}
}
/*
signed main(){
int n;
cin >> n;
initialize(n);
for(int i = 0; i < n; i++){
for(int j = i+1; j < n; j++){
cout << i << ' ' << j << ' ' << hasEdge(i,j) << endl;
}
}
}
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |