#include "game.h"
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
const int MAX_N=3e5+10;
vector<vi> I;
vector<vi> G;
int fr[MAX_N];
int to[MAX_N];
int K,N;
void init(int n, int k) {
K=k;
N=n;
G.resize(n+1);
I.resize(n+1);
for(int i=0;i<=n;i++) fr[i]=1e9;
memset(to,-1,sizeof to);
}
bool updateG(int u){
bool ans=0;
if(to[u]>=fr[u]) return 1;
for(auto &v:G[u]){
int val;
if(u<K) val=u;
else val=fr[u];
if(fr[v]>val){
fr[v]=val;
ans|=updateG(v);
}
}
return ans;
}
bool updateI(int u){
bool ans=0;
if(to[u]>=fr[u]) return 1;
for(auto &v:I[u]){
int val;
if(u<K) val=u;
else val=to[u];
if(val<to[v]){
ans|=updateI(v);
}
}
return ans;
}
int add_teleporter(int u, int v) {
if(u<K && v<K){
if(u>=v) return 1;
return 0;
}
G[u].push_back(v);
I[v].push_back(u);
if(u<K){
to[v]=max(to[v],u);
}
if(v<K){
fr[u]=min(fr[u],v);
}
bool s1=updateG(u);
bool s2=updateI(v);
return s1|s2;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1360 KB |
Output is correct |
2 |
Correct |
1 ms |
1360 KB |
Output is correct |
3 |
Correct |
1 ms |
1360 KB |
Output is correct |
4 |
Correct |
1 ms |
1360 KB |
Output is correct |
5 |
Correct |
1 ms |
1360 KB |
Output is correct |
6 |
Correct |
1 ms |
1360 KB |
Output is correct |
7 |
Correct |
1 ms |
1488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1360 KB |
Output is correct |
2 |
Correct |
1 ms |
1360 KB |
Output is correct |
3 |
Correct |
1 ms |
1360 KB |
Output is correct |
4 |
Correct |
1 ms |
1360 KB |
Output is correct |
5 |
Correct |
1 ms |
1360 KB |
Output is correct |
6 |
Correct |
1 ms |
1360 KB |
Output is correct |
7 |
Correct |
1 ms |
1488 KB |
Output is correct |
8 |
Correct |
1 ms |
1360 KB |
Output is correct |
9 |
Correct |
1 ms |
1360 KB |
Output is correct |
10 |
Incorrect |
1 ms |
1360 KB |
Wrong Answer[1] |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1360 KB |
Output is correct |
2 |
Correct |
1 ms |
1360 KB |
Output is correct |
3 |
Correct |
1 ms |
1360 KB |
Output is correct |
4 |
Correct |
1 ms |
1360 KB |
Output is correct |
5 |
Correct |
1 ms |
1360 KB |
Output is correct |
6 |
Correct |
1 ms |
1360 KB |
Output is correct |
7 |
Correct |
1 ms |
1488 KB |
Output is correct |
8 |
Correct |
1 ms |
1360 KB |
Output is correct |
9 |
Correct |
1 ms |
1360 KB |
Output is correct |
10 |
Incorrect |
1 ms |
1360 KB |
Wrong Answer[1] |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1360 KB |
Output is correct |
2 |
Correct |
1 ms |
1360 KB |
Output is correct |
3 |
Correct |
1 ms |
1360 KB |
Output is correct |
4 |
Correct |
1 ms |
1360 KB |
Output is correct |
5 |
Correct |
1 ms |
1360 KB |
Output is correct |
6 |
Correct |
1 ms |
1360 KB |
Output is correct |
7 |
Correct |
1 ms |
1488 KB |
Output is correct |
8 |
Correct |
1 ms |
1360 KB |
Output is correct |
9 |
Correct |
1 ms |
1360 KB |
Output is correct |
10 |
Incorrect |
1 ms |
1360 KB |
Wrong Answer[1] |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1360 KB |
Output is correct |
2 |
Correct |
1 ms |
1360 KB |
Output is correct |
3 |
Correct |
1 ms |
1360 KB |
Output is correct |
4 |
Correct |
1 ms |
1360 KB |
Output is correct |
5 |
Correct |
1 ms |
1360 KB |
Output is correct |
6 |
Correct |
1 ms |
1360 KB |
Output is correct |
7 |
Correct |
1 ms |
1488 KB |
Output is correct |
8 |
Correct |
1 ms |
1360 KB |
Output is correct |
9 |
Correct |
1 ms |
1360 KB |
Output is correct |
10 |
Incorrect |
1 ms |
1360 KB |
Wrong Answer[1] |
11 |
Halted |
0 ms |
0 KB |
- |