#include <bits/stdc++.h>
#include "game.h"
using namespace std;
constexpr size_t N = 1000;
int n, k;
vector<int> g[N], rg[N], postorder;
bitset<N> visited;
void init(int n_, int k_)
{
n = n_, k = k_;
for (int i = 0; i + 1 < k; ++i)
g[i].push_back(i + 1), rg[i + 1].push_back(i);
}
void dfs_postorder(int u)
{
visited[u] = 1;
for (int const &v : g[u])
if (!visited[v])
dfs_postorder(v);
postorder.push_back(u);
}
bool find_scc(int u, int &scc_size)
{
visited[u] = 1;
++scc_size;
if (u < k && scc_size > 1)
return 1;
for (int const &v : rg[u])
if (!visited[v])
{
if (u < k)
return 1;
if (find_scc(v, scc_size))
return 1;
}
return 0;
}
int add_teleporter(int u, int v)
{
if (u < k && u == v)
return 1;
g[u].push_back(v);
rg[v].push_back(u);
visited.reset();
postorder.clear();
for (int i = 0; i < n; ++i)
if (!visited[i])
dfs_postorder(i);
visited.reset();
reverse(postorder.begin(), postorder.end());
for (int const &i : postorder)
if (!visited[i])
{
int scc_size = 0;
if (find_scc(i, scc_size))
return 1;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
356 KB |
Output is correct |
8 |
Correct |
0 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
0 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
356 KB |
Output is correct |
8 |
Correct |
0 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
0 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
11 ms |
336 KB |
Output is correct |
21 |
Correct |
3 ms |
336 KB |
Output is correct |
22 |
Correct |
13 ms |
400 KB |
Output is correct |
23 |
Correct |
14 ms |
488 KB |
Output is correct |
24 |
Correct |
15 ms |
336 KB |
Output is correct |
25 |
Correct |
76 ms |
432 KB |
Output is correct |
26 |
Correct |
92 ms |
412 KB |
Output is correct |
27 |
Correct |
73 ms |
428 KB |
Output is correct |
28 |
Correct |
35 ms |
428 KB |
Output is correct |
29 |
Correct |
76 ms |
420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
356 KB |
Output is correct |
8 |
Correct |
0 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
0 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
11 ms |
336 KB |
Output is correct |
21 |
Correct |
3 ms |
336 KB |
Output is correct |
22 |
Correct |
13 ms |
400 KB |
Output is correct |
23 |
Correct |
14 ms |
488 KB |
Output is correct |
24 |
Correct |
15 ms |
336 KB |
Output is correct |
25 |
Correct |
76 ms |
432 KB |
Output is correct |
26 |
Correct |
92 ms |
412 KB |
Output is correct |
27 |
Correct |
73 ms |
428 KB |
Output is correct |
28 |
Correct |
35 ms |
428 KB |
Output is correct |
29 |
Correct |
76 ms |
420 KB |
Output is correct |
30 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
31 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
356 KB |
Output is correct |
8 |
Correct |
0 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
0 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
11 ms |
336 KB |
Output is correct |
21 |
Correct |
3 ms |
336 KB |
Output is correct |
22 |
Correct |
13 ms |
400 KB |
Output is correct |
23 |
Correct |
14 ms |
488 KB |
Output is correct |
24 |
Correct |
15 ms |
336 KB |
Output is correct |
25 |
Correct |
76 ms |
432 KB |
Output is correct |
26 |
Correct |
92 ms |
412 KB |
Output is correct |
27 |
Correct |
73 ms |
428 KB |
Output is correct |
28 |
Correct |
35 ms |
428 KB |
Output is correct |
29 |
Correct |
76 ms |
420 KB |
Output is correct |
30 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
31 |
Halted |
0 ms |
0 KB |
- |