#include <bits/stdc++.h>
#include "game.h"
using namespace std;
constexpr size_t N = 30000;
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 |
1616 KB |
Output is correct |
2 |
Correct |
1 ms |
1616 KB |
Output is correct |
3 |
Correct |
2 ms |
1616 KB |
Output is correct |
4 |
Correct |
1 ms |
1616 KB |
Output is correct |
5 |
Correct |
1 ms |
1616 KB |
Output is correct |
6 |
Correct |
2 ms |
1616 KB |
Output is correct |
7 |
Correct |
1 ms |
1616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1616 KB |
Output is correct |
2 |
Correct |
1 ms |
1616 KB |
Output is correct |
3 |
Correct |
2 ms |
1616 KB |
Output is correct |
4 |
Correct |
1 ms |
1616 KB |
Output is correct |
5 |
Correct |
1 ms |
1616 KB |
Output is correct |
6 |
Correct |
2 ms |
1616 KB |
Output is correct |
7 |
Correct |
1 ms |
1616 KB |
Output is correct |
8 |
Correct |
2 ms |
1616 KB |
Output is correct |
9 |
Correct |
1 ms |
1616 KB |
Output is correct |
10 |
Correct |
1 ms |
1648 KB |
Output is correct |
11 |
Correct |
1 ms |
1616 KB |
Output is correct |
12 |
Correct |
2 ms |
1616 KB |
Output is correct |
13 |
Correct |
1 ms |
1740 KB |
Output is correct |
14 |
Correct |
1 ms |
1616 KB |
Output is correct |
15 |
Correct |
1 ms |
1616 KB |
Output is correct |
16 |
Correct |
2 ms |
1740 KB |
Output is correct |
17 |
Correct |
1 ms |
1616 KB |
Output is correct |
18 |
Correct |
2 ms |
1616 KB |
Output is correct |
19 |
Correct |
2 ms |
1668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1616 KB |
Output is correct |
2 |
Correct |
1 ms |
1616 KB |
Output is correct |
3 |
Correct |
2 ms |
1616 KB |
Output is correct |
4 |
Correct |
1 ms |
1616 KB |
Output is correct |
5 |
Correct |
1 ms |
1616 KB |
Output is correct |
6 |
Correct |
2 ms |
1616 KB |
Output is correct |
7 |
Correct |
1 ms |
1616 KB |
Output is correct |
8 |
Correct |
2 ms |
1616 KB |
Output is correct |
9 |
Correct |
1 ms |
1616 KB |
Output is correct |
10 |
Correct |
1 ms |
1648 KB |
Output is correct |
11 |
Correct |
1 ms |
1616 KB |
Output is correct |
12 |
Correct |
2 ms |
1616 KB |
Output is correct |
13 |
Correct |
1 ms |
1740 KB |
Output is correct |
14 |
Correct |
1 ms |
1616 KB |
Output is correct |
15 |
Correct |
1 ms |
1616 KB |
Output is correct |
16 |
Correct |
2 ms |
1740 KB |
Output is correct |
17 |
Correct |
1 ms |
1616 KB |
Output is correct |
18 |
Correct |
2 ms |
1616 KB |
Output is correct |
19 |
Correct |
2 ms |
1668 KB |
Output is correct |
20 |
Correct |
12 ms |
1752 KB |
Output is correct |
21 |
Correct |
2 ms |
1616 KB |
Output is correct |
22 |
Correct |
12 ms |
1784 KB |
Output is correct |
23 |
Correct |
15 ms |
1772 KB |
Output is correct |
24 |
Correct |
16 ms |
1744 KB |
Output is correct |
25 |
Correct |
80 ms |
1804 KB |
Output is correct |
26 |
Correct |
91 ms |
1788 KB |
Output is correct |
27 |
Correct |
72 ms |
1812 KB |
Output is correct |
28 |
Correct |
37 ms |
1784 KB |
Output is correct |
29 |
Correct |
69 ms |
1792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1616 KB |
Output is correct |
2 |
Correct |
1 ms |
1616 KB |
Output is correct |
3 |
Correct |
2 ms |
1616 KB |
Output is correct |
4 |
Correct |
1 ms |
1616 KB |
Output is correct |
5 |
Correct |
1 ms |
1616 KB |
Output is correct |
6 |
Correct |
2 ms |
1616 KB |
Output is correct |
7 |
Correct |
1 ms |
1616 KB |
Output is correct |
8 |
Correct |
2 ms |
1616 KB |
Output is correct |
9 |
Correct |
1 ms |
1616 KB |
Output is correct |
10 |
Correct |
1 ms |
1648 KB |
Output is correct |
11 |
Correct |
1 ms |
1616 KB |
Output is correct |
12 |
Correct |
2 ms |
1616 KB |
Output is correct |
13 |
Correct |
1 ms |
1740 KB |
Output is correct |
14 |
Correct |
1 ms |
1616 KB |
Output is correct |
15 |
Correct |
1 ms |
1616 KB |
Output is correct |
16 |
Correct |
2 ms |
1740 KB |
Output is correct |
17 |
Correct |
1 ms |
1616 KB |
Output is correct |
18 |
Correct |
2 ms |
1616 KB |
Output is correct |
19 |
Correct |
2 ms |
1668 KB |
Output is correct |
20 |
Correct |
12 ms |
1752 KB |
Output is correct |
21 |
Correct |
2 ms |
1616 KB |
Output is correct |
22 |
Correct |
12 ms |
1784 KB |
Output is correct |
23 |
Correct |
15 ms |
1772 KB |
Output is correct |
24 |
Correct |
16 ms |
1744 KB |
Output is correct |
25 |
Correct |
80 ms |
1804 KB |
Output is correct |
26 |
Correct |
91 ms |
1788 KB |
Output is correct |
27 |
Correct |
72 ms |
1812 KB |
Output is correct |
28 |
Correct |
37 ms |
1784 KB |
Output is correct |
29 |
Correct |
69 ms |
1792 KB |
Output is correct |
30 |
Execution timed out |
4027 ms |
2416 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1616 KB |
Output is correct |
2 |
Correct |
1 ms |
1616 KB |
Output is correct |
3 |
Correct |
2 ms |
1616 KB |
Output is correct |
4 |
Correct |
1 ms |
1616 KB |
Output is correct |
5 |
Correct |
1 ms |
1616 KB |
Output is correct |
6 |
Correct |
2 ms |
1616 KB |
Output is correct |
7 |
Correct |
1 ms |
1616 KB |
Output is correct |
8 |
Correct |
2 ms |
1616 KB |
Output is correct |
9 |
Correct |
1 ms |
1616 KB |
Output is correct |
10 |
Correct |
1 ms |
1648 KB |
Output is correct |
11 |
Correct |
1 ms |
1616 KB |
Output is correct |
12 |
Correct |
2 ms |
1616 KB |
Output is correct |
13 |
Correct |
1 ms |
1740 KB |
Output is correct |
14 |
Correct |
1 ms |
1616 KB |
Output is correct |
15 |
Correct |
1 ms |
1616 KB |
Output is correct |
16 |
Correct |
2 ms |
1740 KB |
Output is correct |
17 |
Correct |
1 ms |
1616 KB |
Output is correct |
18 |
Correct |
2 ms |
1616 KB |
Output is correct |
19 |
Correct |
2 ms |
1668 KB |
Output is correct |
20 |
Correct |
12 ms |
1752 KB |
Output is correct |
21 |
Correct |
2 ms |
1616 KB |
Output is correct |
22 |
Correct |
12 ms |
1784 KB |
Output is correct |
23 |
Correct |
15 ms |
1772 KB |
Output is correct |
24 |
Correct |
16 ms |
1744 KB |
Output is correct |
25 |
Correct |
80 ms |
1804 KB |
Output is correct |
26 |
Correct |
91 ms |
1788 KB |
Output is correct |
27 |
Correct |
72 ms |
1812 KB |
Output is correct |
28 |
Correct |
37 ms |
1784 KB |
Output is correct |
29 |
Correct |
69 ms |
1792 KB |
Output is correct |
30 |
Execution timed out |
4027 ms |
2416 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |