제출 #711998

#제출 시각아이디문제언어결과실행 시간메모리
711998thimote75게임 (IOI14_game)C++14
42 / 100
1079 ms756 KiB
#include "game.h"
#include <bits/stdc++.h>

using namespace std;

#define graph vector<set<int>>

graph n_roads;

bool has_road (int a, int b) {
    return a != b && n_roads[a].find(b) == n_roads[a].end();
}

vector<int> visited;
int stage = 0;
int nbNodes;
bool find (int pos, int target) {
    if (pos == target) return true;
    if (visited[pos] == stage) return false;
    visited[pos] = stage;

    for (int n = 0; n < nbNodes; n ++)
        if (has_road(pos, n) && find(n, target))
            return true;

    return false;
}

void initialize(int n) {
    nbNodes = n;
    n_roads.resize(n);
    visited.resize(n, -1);
}

int hasEdge(int u, int v) {
    n_roads[u].insert(v);
    n_roads[v].insert(u);

    stage ++;
    if (find(u, v))
        return 0;
    
    n_roads[u].erase(v);
    n_roads[v].erase(u);

    return 1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...