#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
vector<int> g[maxn], _g[maxn];
int mink[maxn], maxk[maxn];
int n, k;
void init(int _n, int _k) {
n = _n, k = _k;
for (int i = 0; i + 1 < k; ++i) {
g[i].push_back(i + 1);
_g[i + 1].push_back(i);
}
for (int i = 0; i < k; ++i) {
mink[i] = maxk[i] = i;
}
for (int i = k; i < n; ++i) {
mink[i] = k;
maxk[i] = -1;
}
}
bool dfs_min(int v, int val) {
if (mink[v] <= val || v < k) {
return false;
}
mink[v] = val;
if (mink[v] <= maxk[v]) {
return true;
}
for (auto u : _g[v]) {
if (dfs_min(u, val)) {
return true;
}
}
return false;
}
bool dfs_max(int v, int val) {
if (maxk[v] >= val || v < k) {
return false;
}
maxk[v] = val;
if (mink[v] <= maxk[v]) {
return true;
}
for (auto u : g[v]) {
if (dfs_max(u, val)) {
return true;
}
}
return false;
}
int add_teleporter(int u, int v) {
if (u == v && u < k) {
return 1;
}
if (u > v && u < k) {
return 1;
}
if (u < k && v < k) {
return 0;
}
g[u].push_back(v);
_g[v].push_back(u);
return dfs_max(v, maxk[u]) || dfs_min(u, mink[v]);
}
// int main() {
// int N, M, K;
// cin >> N >> M >> K;
// std::vector<int> u(M), v(M);
// for (int i = 0; i < M; ++i) {
// cin >> u[i] >> v[i];
// }
// 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;
// }
// }
// cout << i;
// return 0;
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
7 ms |
14316 KB |
Output is correct |
3 |
Correct |
7 ms |
14288 KB |
Output is correct |
4 |
Correct |
7 ms |
14288 KB |
Output is correct |
5 |
Correct |
7 ms |
14288 KB |
Output is correct |
6 |
Correct |
7 ms |
14416 KB |
Output is correct |
7 |
Correct |
9 ms |
14416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
7 ms |
14316 KB |
Output is correct |
3 |
Correct |
7 ms |
14288 KB |
Output is correct |
4 |
Correct |
7 ms |
14288 KB |
Output is correct |
5 |
Correct |
7 ms |
14288 KB |
Output is correct |
6 |
Correct |
7 ms |
14416 KB |
Output is correct |
7 |
Correct |
9 ms |
14416 KB |
Output is correct |
8 |
Correct |
7 ms |
14288 KB |
Output is correct |
9 |
Correct |
6 ms |
14288 KB |
Output is correct |
10 |
Correct |
7 ms |
14360 KB |
Output is correct |
11 |
Correct |
6 ms |
14288 KB |
Output is correct |
12 |
Correct |
6 ms |
14288 KB |
Output is correct |
13 |
Correct |
6 ms |
14288 KB |
Output is correct |
14 |
Correct |
6 ms |
14288 KB |
Output is correct |
15 |
Correct |
6 ms |
14288 KB |
Output is correct |
16 |
Correct |
7 ms |
14288 KB |
Output is correct |
17 |
Correct |
7 ms |
14416 KB |
Output is correct |
18 |
Correct |
8 ms |
14288 KB |
Output is correct |
19 |
Correct |
7 ms |
14288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
7 ms |
14316 KB |
Output is correct |
3 |
Correct |
7 ms |
14288 KB |
Output is correct |
4 |
Correct |
7 ms |
14288 KB |
Output is correct |
5 |
Correct |
7 ms |
14288 KB |
Output is correct |
6 |
Correct |
7 ms |
14416 KB |
Output is correct |
7 |
Correct |
9 ms |
14416 KB |
Output is correct |
8 |
Correct |
7 ms |
14288 KB |
Output is correct |
9 |
Correct |
6 ms |
14288 KB |
Output is correct |
10 |
Correct |
7 ms |
14360 KB |
Output is correct |
11 |
Correct |
6 ms |
14288 KB |
Output is correct |
12 |
Correct |
6 ms |
14288 KB |
Output is correct |
13 |
Correct |
6 ms |
14288 KB |
Output is correct |
14 |
Correct |
6 ms |
14288 KB |
Output is correct |
15 |
Correct |
6 ms |
14288 KB |
Output is correct |
16 |
Correct |
7 ms |
14288 KB |
Output is correct |
17 |
Correct |
7 ms |
14416 KB |
Output is correct |
18 |
Correct |
8 ms |
14288 KB |
Output is correct |
19 |
Correct |
7 ms |
14288 KB |
Output is correct |
20 |
Correct |
7 ms |
14416 KB |
Output is correct |
21 |
Correct |
8 ms |
14312 KB |
Output is correct |
22 |
Correct |
8 ms |
14416 KB |
Output is correct |
23 |
Correct |
7 ms |
14416 KB |
Output is correct |
24 |
Correct |
9 ms |
14416 KB |
Output is correct |
25 |
Correct |
9 ms |
14416 KB |
Output is correct |
26 |
Correct |
9 ms |
14416 KB |
Output is correct |
27 |
Correct |
7 ms |
14416 KB |
Output is correct |
28 |
Correct |
8 ms |
14428 KB |
Output is correct |
29 |
Correct |
7 ms |
14416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
7 ms |
14316 KB |
Output is correct |
3 |
Correct |
7 ms |
14288 KB |
Output is correct |
4 |
Correct |
7 ms |
14288 KB |
Output is correct |
5 |
Correct |
7 ms |
14288 KB |
Output is correct |
6 |
Correct |
7 ms |
14416 KB |
Output is correct |
7 |
Correct |
9 ms |
14416 KB |
Output is correct |
8 |
Correct |
7 ms |
14288 KB |
Output is correct |
9 |
Correct |
6 ms |
14288 KB |
Output is correct |
10 |
Correct |
7 ms |
14360 KB |
Output is correct |
11 |
Correct |
6 ms |
14288 KB |
Output is correct |
12 |
Correct |
6 ms |
14288 KB |
Output is correct |
13 |
Correct |
6 ms |
14288 KB |
Output is correct |
14 |
Correct |
6 ms |
14288 KB |
Output is correct |
15 |
Correct |
6 ms |
14288 KB |
Output is correct |
16 |
Correct |
7 ms |
14288 KB |
Output is correct |
17 |
Correct |
7 ms |
14416 KB |
Output is correct |
18 |
Correct |
8 ms |
14288 KB |
Output is correct |
19 |
Correct |
7 ms |
14288 KB |
Output is correct |
20 |
Correct |
7 ms |
14416 KB |
Output is correct |
21 |
Correct |
8 ms |
14312 KB |
Output is correct |
22 |
Correct |
8 ms |
14416 KB |
Output is correct |
23 |
Correct |
7 ms |
14416 KB |
Output is correct |
24 |
Correct |
9 ms |
14416 KB |
Output is correct |
25 |
Correct |
9 ms |
14416 KB |
Output is correct |
26 |
Correct |
9 ms |
14416 KB |
Output is correct |
27 |
Correct |
7 ms |
14416 KB |
Output is correct |
28 |
Correct |
8 ms |
14428 KB |
Output is correct |
29 |
Correct |
7 ms |
14416 KB |
Output is correct |
30 |
Correct |
23 ms |
15784 KB |
Output is correct |
31 |
Correct |
10 ms |
15056 KB |
Output is correct |
32 |
Correct |
20 ms |
16608 KB |
Output is correct |
33 |
Correct |
20 ms |
16456 KB |
Output is correct |
34 |
Correct |
895 ms |
17400 KB |
Output is correct |
35 |
Correct |
311 ms |
17004 KB |
Output is correct |
36 |
Correct |
36 ms |
16532 KB |
Output is correct |
37 |
Correct |
32 ms |
16416 KB |
Output is correct |
38 |
Correct |
25 ms |
16236 KB |
Output is correct |
39 |
Correct |
28 ms |
16200 KB |
Output is correct |
40 |
Correct |
738 ms |
17504 KB |
Output is correct |
41 |
Correct |
147 ms |
16532 KB |
Output is correct |
42 |
Correct |
101 ms |
16532 KB |
Output is correct |
43 |
Correct |
32 ms |
17096 KB |
Output is correct |
44 |
Correct |
648 ms |
17480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
7 ms |
14316 KB |
Output is correct |
3 |
Correct |
7 ms |
14288 KB |
Output is correct |
4 |
Correct |
7 ms |
14288 KB |
Output is correct |
5 |
Correct |
7 ms |
14288 KB |
Output is correct |
6 |
Correct |
7 ms |
14416 KB |
Output is correct |
7 |
Correct |
9 ms |
14416 KB |
Output is correct |
8 |
Correct |
7 ms |
14288 KB |
Output is correct |
9 |
Correct |
6 ms |
14288 KB |
Output is correct |
10 |
Correct |
7 ms |
14360 KB |
Output is correct |
11 |
Correct |
6 ms |
14288 KB |
Output is correct |
12 |
Correct |
6 ms |
14288 KB |
Output is correct |
13 |
Correct |
6 ms |
14288 KB |
Output is correct |
14 |
Correct |
6 ms |
14288 KB |
Output is correct |
15 |
Correct |
6 ms |
14288 KB |
Output is correct |
16 |
Correct |
7 ms |
14288 KB |
Output is correct |
17 |
Correct |
7 ms |
14416 KB |
Output is correct |
18 |
Correct |
8 ms |
14288 KB |
Output is correct |
19 |
Correct |
7 ms |
14288 KB |
Output is correct |
20 |
Correct |
7 ms |
14416 KB |
Output is correct |
21 |
Correct |
8 ms |
14312 KB |
Output is correct |
22 |
Correct |
8 ms |
14416 KB |
Output is correct |
23 |
Correct |
7 ms |
14416 KB |
Output is correct |
24 |
Correct |
9 ms |
14416 KB |
Output is correct |
25 |
Correct |
9 ms |
14416 KB |
Output is correct |
26 |
Correct |
9 ms |
14416 KB |
Output is correct |
27 |
Correct |
7 ms |
14416 KB |
Output is correct |
28 |
Correct |
8 ms |
14428 KB |
Output is correct |
29 |
Correct |
7 ms |
14416 KB |
Output is correct |
30 |
Correct |
23 ms |
15784 KB |
Output is correct |
31 |
Correct |
10 ms |
15056 KB |
Output is correct |
32 |
Correct |
20 ms |
16608 KB |
Output is correct |
33 |
Correct |
20 ms |
16456 KB |
Output is correct |
34 |
Correct |
895 ms |
17400 KB |
Output is correct |
35 |
Correct |
311 ms |
17004 KB |
Output is correct |
36 |
Correct |
36 ms |
16532 KB |
Output is correct |
37 |
Correct |
32 ms |
16416 KB |
Output is correct |
38 |
Correct |
25 ms |
16236 KB |
Output is correct |
39 |
Correct |
28 ms |
16200 KB |
Output is correct |
40 |
Correct |
738 ms |
17504 KB |
Output is correct |
41 |
Correct |
147 ms |
16532 KB |
Output is correct |
42 |
Correct |
101 ms |
16532 KB |
Output is correct |
43 |
Correct |
32 ms |
17096 KB |
Output is correct |
44 |
Correct |
648 ms |
17480 KB |
Output is correct |
45 |
Correct |
200 ms |
28020 KB |
Output is correct |
46 |
Correct |
11 ms |
17232 KB |
Output is correct |
47 |
Correct |
11 ms |
17232 KB |
Output is correct |
48 |
Correct |
286 ms |
39488 KB |
Output is correct |
49 |
Correct |
198 ms |
35452 KB |
Output is correct |
50 |
Execution timed out |
4073 ms |
40264 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |