Submission #414519

#TimeUsernameProblemLanguageResultExecution timeMemory
414519illyakrGame (IOI14_game)C++14
42 / 100
1086 ms3528 KiB
#include <bits/stdc++.h>
#include "game.h"

using namespace std;

int was[1510][1510];
int N;
void initialize(int n) {
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            was[i][j] = -1;
        }
        was[i][i] = 0;
    }
    N = n;
}

bool used[1510];
void dfs(int v) {
    used[v] = true;
    for (int i = 1; i <= N; i++) {
        if (was[v][i] == 0)continue;
        if (used[i])continue;
        dfs(i);
    }
}


int hasEdge(int u, int v) {
    u++; v++;
    if (was[u][v] != -1)return was[u][v];
    for (int i = 1; i <= N; i++)used[i] = false;
    was[u][v] = 0;
    was[v][u] = 0;
    dfs(1);
    for (int i = 1; i <= N; i++) {
        if (!used[i]) {
            was[u][v] = 1;
            was[v][u] = 1;
            return 1;
        }
    }
    return 0;
}

/**
4
0 3
1 0
0 2
3 1
1 2
2 3

4
0 3
2 0
0 1
1 2
1 3
2 3

4
0 1
3 0
1 2
0 2
3 1
2 3
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...