#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 15e4, B = 30;
int n, m, p, q, adj[2][N];
pair<int, int> dp[2][B][N];
int f(int x, int k) {
pair<int, int> pr = make_pair(0, x);
for (int i = 29; i >= 0; i--) {
if ((k >> i) & 1) {
pr = dp[pr.first][i][pr.second];
}
}
return pr.second;
}
void count_routes(int n, int m, int p, int R[][2], int q, int G[])
{
for (int i = 0; i < n; i++) {
adj[0][i] = adj[1][i] = -1;
}
for (int i = 0; i < m; i++) {
int x = R[i][0];
int y = R[i][1];
if (adj[0][x] == -1) {
adj[0][x] = adj[1][x] = y;
}
else if (adj[1][x] == adj[0][x]) {
adj[1][x] = y;
}
if (adj[0][y] == -1) {
adj[0][y] = adj[1][y] = x;
}
else if (adj[1][y] == adj[0][y]) {
adj[1][y] = x;
}
}
for (int i = 0; i < n; i++) {
int x = adj[0][i];
if (x == -1) {
dp[0][0][i] = make_pair(0, i);
}
else {
dp[0][0][i] = make_pair((adj[0][x] == i ? 1 : 0), x);
}
x = adj[1][i];
if (x == -1) {
dp[1][0][i] = make_pair(0, i);
}
else {
dp[1][0][i] = make_pair((adj[0][x] == i ? 1 : 0), x);
}
}
for (int i = 1; i < B; i++) {
for (int j = 0; j < n; j++) {
pair<int, int> mid = dp[0][i-1][j];
dp[0][i][j] = dp[mid.first][i-1][mid.second];
mid = dp[1][i-1][j];
dp[1][i][j] = dp[mid.first][i-1][mid.second];
}
}
cin >> q;
for (int i = 0; i < q; i++) {
int x = G[i];
int ans = 0;
for (int j = 0; j < n; j++) {
if (f(j, x) == p) ans++;
}
answer(ans);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
72024 KB |
Output is correct |
2 |
Correct |
8 ms |
72028 KB |
Output is correct |
3 |
Correct |
8 ms |
72028 KB |
Output is correct |
4 |
Correct |
8 ms |
72024 KB |
Output is correct |
5 |
Correct |
7 ms |
72028 KB |
Output is correct |
6 |
Correct |
8 ms |
72028 KB |
Output is correct |
7 |
Correct |
8 ms |
72128 KB |
Output is correct |
8 |
Correct |
9 ms |
72024 KB |
Output is correct |
9 |
Correct |
9 ms |
72028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
72024 KB |
Output is correct |
2 |
Correct |
8 ms |
72028 KB |
Output is correct |
3 |
Correct |
8 ms |
72028 KB |
Output is correct |
4 |
Correct |
8 ms |
72024 KB |
Output is correct |
5 |
Correct |
7 ms |
72028 KB |
Output is correct |
6 |
Correct |
8 ms |
72028 KB |
Output is correct |
7 |
Correct |
8 ms |
72128 KB |
Output is correct |
8 |
Correct |
9 ms |
72024 KB |
Output is correct |
9 |
Correct |
9 ms |
72028 KB |
Output is correct |
10 |
Correct |
9 ms |
72028 KB |
Output is correct |
11 |
Correct |
12 ms |
72364 KB |
Output is correct |
12 |
Correct |
19 ms |
74328 KB |
Output is correct |
13 |
Correct |
27 ms |
74332 KB |
Output is correct |
14 |
Correct |
45 ms |
74836 KB |
Output is correct |
15 |
Correct |
42 ms |
74412 KB |
Output is correct |
16 |
Correct |
36 ms |
74332 KB |
Output is correct |
17 |
Correct |
34 ms |
74452 KB |
Output is correct |
18 |
Correct |
19 ms |
74328 KB |
Output is correct |
19 |
Correct |
42 ms |
74460 KB |
Output is correct |
20 |
Correct |
41 ms |
74404 KB |
Output is correct |
21 |
Correct |
42 ms |
74324 KB |
Output is correct |
22 |
Correct |
35 ms |
74428 KB |
Output is correct |
23 |
Correct |
44 ms |
74420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
72024 KB |
Output is correct |
2 |
Correct |
8 ms |
72028 KB |
Output is correct |
3 |
Correct |
8 ms |
72028 KB |
Output is correct |
4 |
Correct |
8 ms |
72024 KB |
Output is correct |
5 |
Correct |
7 ms |
72028 KB |
Output is correct |
6 |
Correct |
8 ms |
72028 KB |
Output is correct |
7 |
Correct |
8 ms |
72128 KB |
Output is correct |
8 |
Correct |
9 ms |
72024 KB |
Output is correct |
9 |
Correct |
9 ms |
72028 KB |
Output is correct |
10 |
Correct |
9 ms |
72028 KB |
Output is correct |
11 |
Correct |
12 ms |
72364 KB |
Output is correct |
12 |
Correct |
19 ms |
74328 KB |
Output is correct |
13 |
Correct |
27 ms |
74332 KB |
Output is correct |
14 |
Correct |
45 ms |
74836 KB |
Output is correct |
15 |
Correct |
42 ms |
74412 KB |
Output is correct |
16 |
Correct |
36 ms |
74332 KB |
Output is correct |
17 |
Correct |
34 ms |
74452 KB |
Output is correct |
18 |
Correct |
19 ms |
74328 KB |
Output is correct |
19 |
Correct |
42 ms |
74460 KB |
Output is correct |
20 |
Correct |
41 ms |
74404 KB |
Output is correct |
21 |
Correct |
42 ms |
74324 KB |
Output is correct |
22 |
Correct |
35 ms |
74428 KB |
Output is correct |
23 |
Correct |
44 ms |
74420 KB |
Output is correct |
24 |
Correct |
12 ms |
72252 KB |
Output is correct |
25 |
Correct |
1817 ms |
72404 KB |
Output is correct |
26 |
Correct |
3384 ms |
74460 KB |
Output is correct |
27 |
Execution timed out |
5094 ms |
74452 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |