#include "game.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int K;
int N;
vector<int> mini;
vector<int> maxi;
vector<vector<int>> teapuntan;
vector<vector<int>> apuntas;
void init(int n, int k) {
N=n;
K=k;
mini.resize( n, 1e9);
maxi.resize(n, -1);
teapuntan.resize(n);
apuntas.resize(n);
}
int add_teleporter(int u, int v) {
if(u<K && v<K){
if(u>=v) return 1;
return 0;
}
if(u<K){
queue<int> q;
q.push(v);
vector<bool> visited (N, 0);
while(!q.empty()){
int x=q.front();
q.pop();
if(visited[x]) continue;
visited[x]=true;
if(maxi[x]>u) continue;
maxi[x]=u;
if(maxi[x]>=mini[x]) return 1;
for(int y: apuntas[x]){
if(visited[y]) continue;
q.push(y);
}
}
}
else if(v<K){
queue<int> q;
q.push(u);
vector<bool> visited(N,0);
while(!q.empty()){
int x=q.front();
q.pop();
if(visited[x]) continue;
visited[x]=true;
if(mini[x]<v) continue;
mini[x]=v;
if(maxi[x]>=mini[x]) return 1;
for(int y:teapuntan[x]){
if(visited[y]) continue;
q.push(y);
}
}
}
else{
apuntas[u].pb(v);
teapuntan[v].pb(u);
queue<int> q;
q.push(v);
vector<bool> visited1 (N, false);
while(!q.empty()){
int x=q.front();
q.pop();
if(visited1[x]) continue;
visited1[x]=1;
if(maxi[x]>maxi[u]) continue;
maxi[x]=maxi[u];
if(maxi[x]>=mini[x]) return 1;
for(int y: apuntas[x]){
if(visited1[y]) continue;
q.push(y);
}
}
vector<bool> visited2 (N, 0);
q.push(u);
while(!q.empty()){
int x=q.front();
q.pop();
if(visited2[x]) continue;
visited2[x]=1;
if(mini[x]<mini[v]) continue;
mini[x]=mini[v];
if(maxi[x]>=mini[x]) return 1;
for(int y:teapuntan[x]){
if(visited2[y]) continue;
q.push(y);
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
3 ms |
344 KB |
Output is correct |
25 |
Correct |
3 ms |
344 KB |
Output is correct |
26 |
Correct |
6 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
2 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
3 ms |
344 KB |
Output is correct |
25 |
Correct |
3 ms |
344 KB |
Output is correct |
26 |
Correct |
6 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
2 ms |
600 KB |
Output is correct |
30 |
Correct |
26 ms |
3280 KB |
Output is correct |
31 |
Correct |
6 ms |
2428 KB |
Output is correct |
32 |
Correct |
40 ms |
4168 KB |
Output is correct |
33 |
Correct |
42 ms |
4584 KB |
Output is correct |
34 |
Correct |
954 ms |
3976 KB |
Output is correct |
35 |
Correct |
354 ms |
4764 KB |
Output is correct |
36 |
Correct |
260 ms |
3952 KB |
Output is correct |
37 |
Correct |
384 ms |
4124 KB |
Output is correct |
38 |
Correct |
26 ms |
3672 KB |
Output is correct |
39 |
Correct |
34 ms |
3884 KB |
Output is correct |
40 |
Correct |
789 ms |
4004 KB |
Output is correct |
41 |
Correct |
165 ms |
3580 KB |
Output is correct |
42 |
Correct |
118 ms |
4112 KB |
Output is correct |
43 |
Correct |
88 ms |
4440 KB |
Output is correct |
44 |
Execution timed out |
4100 ms |
4500 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
3 ms |
344 KB |
Output is correct |
25 |
Correct |
3 ms |
344 KB |
Output is correct |
26 |
Correct |
6 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
2 ms |
600 KB |
Output is correct |
30 |
Correct |
26 ms |
3280 KB |
Output is correct |
31 |
Correct |
6 ms |
2428 KB |
Output is correct |
32 |
Correct |
40 ms |
4168 KB |
Output is correct |
33 |
Correct |
42 ms |
4584 KB |
Output is correct |
34 |
Correct |
954 ms |
3976 KB |
Output is correct |
35 |
Correct |
354 ms |
4764 KB |
Output is correct |
36 |
Correct |
260 ms |
3952 KB |
Output is correct |
37 |
Correct |
384 ms |
4124 KB |
Output is correct |
38 |
Correct |
26 ms |
3672 KB |
Output is correct |
39 |
Correct |
34 ms |
3884 KB |
Output is correct |
40 |
Correct |
789 ms |
4004 KB |
Output is correct |
41 |
Correct |
165 ms |
3580 KB |
Output is correct |
42 |
Correct |
118 ms |
4112 KB |
Output is correct |
43 |
Correct |
88 ms |
4440 KB |
Output is correct |
44 |
Execution timed out |
4100 ms |
4500 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |