#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;
bool been[nmax];
int ROOT;
void dfs(int node)
{
if(ok)return;
if(node<ROOT)
{
ok=1;
return;
}
if(been[node])
{
ok=(node==ROOT);
return;
}
been[node]=1;
for(auto w:adj[node])
dfs(w);
}
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<mem_k&&v<mem_k)return 1;
adj[u].push_back(v);
dfs_in(v,in[u]);
bck[v].push_back(u);
dfs_out(u,out[v]);
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;
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14404 KB |
Output is correct |
2 |
Incorrect |
7 ms |
14288 KB |
Wrong Answer[1] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14404 KB |
Output is correct |
2 |
Incorrect |
7 ms |
14288 KB |
Wrong Answer[1] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14404 KB |
Output is correct |
2 |
Incorrect |
7 ms |
14288 KB |
Wrong Answer[1] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14404 KB |
Output is correct |
2 |
Incorrect |
7 ms |
14288 KB |
Wrong Answer[1] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14404 KB |
Output is correct |
2 |
Incorrect |
7 ms |
14288 KB |
Wrong Answer[1] |
3 |
Halted |
0 ms |
0 KB |
- |