This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<game.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;
int n, k, to[N], ro[N];
vector<int> g[N], r[N];
bool ok;
void init(int _n, int _k){
n = _n, k = _k;
ok = 0;
for(int i = 0; i < n; ++i) to[i] = (i < k ? i : -1);
for(int i = 0; i < n; ++i) ro[i] = (i < k ? i : MOD);
for(int i = 0; i < k - 1; ++i) g[i].pb(i+1), r[i+1].pb(i);
}
void check(int v){
if(v<k) return;
ok |= (to[v] >= ro[v]);
}
void dfs(int v){
check(v);
for(int u: g[v]){
if(to[u] < to[v]){
to[u] = to[v];
dfs(u);
}
}
}
void rdfs(int v){
check(v);
for(int u: r[v]){
if(ro[u] > ro[v]){
ro[u] = ro[v];
rdfs(u);
}
}
}
int add_teleporter(int u, int v){
g[u].pb(v);
r[v].pb(u);
if(u < k && v < k && u >= v){
// cout << u << ' '<< v << "u\n";
ok = 1;
}
if(to[v] < to[u]){
to[v] = to[u];
dfs(v);
}
if(ro[u] > ro[v]){
ro[u] = ro[v];
rdfs(u);
}
// for(int i = 0; i < n; ++i) cout << ro[i] << ' ';
return ok;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |