# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1225074 | SpyrosAliv | 게임 (APIO22_game) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
// for each node store the latest special node it can be reached from (from[u])
// and the earliest special node it can reach (to[u])
// when connecting u and v such that to[v] <= from[u] answer is 1
vector<vector<int>> g, rev;
int n, k;
vector<int> from, to;
void inti(int N, int K) {
n = N;
k = K;
g.resize(n+1);
rev.resize(n+1);
from.assign(n+1, -1);
to.resize(n+1, n+1);
for (int i = 1; i <= k; i++) {
from[i] = i;
to[i] = k;
}
for (int i = 1; i < k; i++) {
g[i].push_back(i+1);
rev[i+1].push_back(i);
}
}
void set_to(int u, int val) {
if (to[u] <= val) return;
to[u] = val;
for (auto next: rev[u]) {
set_to(next, val);
}
}
void set_from(int u, int val) {
if (from[u] >= val) return;
from[u] = val;
for (auto next: g[u]) {
set_from(next, val);
}
}
int add_teleporter(int u, int v) {
u++;
v++;
if (to[v] <= from[u]) return 1;
g[u].push_back(v);
set_to(u, to[v]);
set_from(v, from[u]);
return 0;
}