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;
const int nmax=3e5+42;
int mem_n,mem_k;
vector<int> adj[nmax],bck[nmax];
int in[nmax],out[nmax];
void init(int n, int k)
{
mem_n=n;
mem_k=k;
for(int i=1;i<k;i++)
{
adj[i-1].push_back(i);
bck[i].push_back(i-1);
}
for(int i=0;i<k;i++)
in[i]=i,out[i]=i;
for(int i=k;i<n;i++)
in[i]=-1e9,out[i]=1e9;
}
bool ok;
void dfs_in(int node,int val)
{
if(in[node]>=val)return;
in[node]=val;
if(in[node]>=out[node])ok=1;
for(auto w:adj[node])
dfs_in(w,val);
}
void dfs_out(int node,int val)
{
if(out[node]<=val)return;
out[node]=val;
if(in[node]>=out[node])ok=1;
for(auto w:bck[node])
dfs_out(w,val);
}
int add_teleporter(int u, int v)
{
if(u==v&&u<mem_k)return 1;
adj[u].push_back(v);
dfs_in(v,in[u]);
bck[v].push_back(u);
dfs_out(u,out[v]);
//for(int i=0;i<mem_n;i++)cout<<i<<" -> "<<in[i]<<" "<<out[i]<<"\t";cout<<endl;
return ok;
}
/*
namespace {
int read_int() {
int x;
if (scanf("%d", &x) != 1) {
fprintf(stderr, "Error while reading input\n");
exit(1);
}
return x;
}
} // namespace
int main() {
int N = read_int();
int M = read_int();
int K = read_int();
std::vector<int> u(M), v(M);
for (int i = 0; i < M; ++i) {
u[i] = read_int();
v[i] = read_int();
}
init(N, K);
int i;
for (i = 0; i < M; ++i) {
int answer = add_teleporter(u[i], v[i]);
if (answer != 0 && answer != 1) {
i = -1;
break;
} else if (answer == 1) {
break;
}
}
printf("%d\n", i);
return 0;
}
*/
# | 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... |