Submission #613599

#TimeUsernameProblemLanguageResultExecution timeMemory
613599Aldas25Game (APIO22_game)C++17
12 / 100
4096 ms20420 KiB
#include "game.h"

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define f first
#define s second
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;

const int MAXN = 500100;

vi adj[MAXN];
int n, k;
bool vis[MAXN];
bool still[MAXN];
bool cycle = false;
vi was;

void dfs (int v) {
    if (cycle) return;
    was.pb(v);
    vis[v] = true;
    still[v] = true;
    for (int u : adj[v]) {
        if (vis[u]) {
            if (still[u] && u < k) {
                cycle = true;
                return;
            }
        } else dfs(u);
    }

    still[v] = false;
}

void init(int N, int K) {
    n = N;
    k = K;
    FOR(i, 0, k-2) adj[i].pb(i+1);
}

int add_teleporter(int u, int v) {
    adj[u].pb(v);
    cycle = false;
    //FOR(i, 0,n-1) vis[i] = false;
    dfs(0);
    for (int x : was) vis[x] = false;
    return cycle;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...