제출 #103516

#제출 시각아이디문제언어결과실행 시간메모리
103516SecretAgent007게임 (IOI14_game)C++17
0 / 100
2 ms384 KiB
# 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...