제출 #1339722

#제출 시각아이디문제언어결과실행 시간메모리
1339722icebear게임 (APIO22_game)C++20
0 / 100
2 ms344 KiB
/* AUTHOR: TUAN ANH - BUI */
// ~~ icebear ~~
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

template<class X, class Y>
    bool minimize(X &x, const Y &y) {
        if (x > y) return x = y, true;
        return false;
    }

template<class X, class Y>
    bool maximize(X &x, const Y &y) {
        if (x < y) return x = y, true;
        return false;
    }

#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define MASK(i) (1LL << (i))
#define BIT(S, i) (((S) >> (i)) & 1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "icebear"
/*END OF TEMPLATE. ICEBEAR AND THE CAT WILL WIN TST26 */

const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 27092008;
const ll INF  = (ll)1e18 + 27092008;
const int N = 3e5 + 5;
int n, k;
vector<int> G[N];
int num[N], low[N], timer = 0;
stack<int> st;

bool dfs(int u) {
    num[u] = low[u] = ++timer;
    st.push(u);
    for(int v : G[u]) {
        if (num[v]) minimize(low[u], num[v]);
        else {
            if (dfs(v)) return true;
            minimize(low[u], low[v]);
        }
    }
    if (num[u] == low[u]) {
        int v, sz = 0;
        bool ok = false;
        do {
            v = st.top(); st.pop();
            if (v < k) ok = true;
            sz++;
        } while(v != u);
        if (sz > 1 && ok) return true;
    }
    return false;
}

void init(int N, int K) {
    n = N; k = K;
    REP(i, K - 1) G[i].pb(i + 1);
}

bool add_teleporter(int u, int v) {
    G[u].pb(v);
    REP(i, n) num[i] = low[i] = false;
    timer = 0;
    st = stack<int>();
    return dfs(0);
}

#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...