Submission #743741

# Submission time Handle Problem Language Result Execution time Memory
743741 2023-05-17T20:44:23 Z Patrick Game (APIO22_game) C++17
0 / 100
1 ms 208 KB
#include "game.h"

#include <queue>
#include <vector>
using namespace std;

int N, K;
vector<bool> reach;
vector<vector<int>> es;

void init(int n, int k) {
    reach = vector<bool>(n);
    es = vector<vector<int>>(n);
    N = n, K = k;
}

int markreach(int u) {
    deque<int> q;
    q.push_back(u);
    while (q.size()) {
        int x = q.front();
        q.pop_front();
        for (int e : es[x]) {
            if (!reach[e]) {
                reach[e] = 1;
                q.push_back(e);
                if (e < K) return 1;
            }
        }
    }
    return 0;
}

int add_teleporter(int u, int v) {
    if (u == v) {
        return u < K;
    }
    if (u < K) {
        if (v < K) return 1;
        if (!reach[v]) {
            reach[v] = 1;
            return markreach(v);
        } else {
            return 0;
        }
    } else {
        if (reach[u]) {
            if (v < K) return 1;
            reach[v] = 1;
            return markreach(v);
        } else {
            es[u].push_back(v);
            return 0;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Incorrect 1 ms 208 KB Wrong Answer[1]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Incorrect 1 ms 208 KB Wrong Answer[1]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Incorrect 1 ms 208 KB Wrong Answer[1]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Incorrect 1 ms 208 KB Wrong Answer[1]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Incorrect 1 ms 208 KB Wrong Answer[1]
3 Halted 0 ms 0 KB -