#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define pb push_back
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){
int n = N, m = M;
vector<pair<int, int>> vec[n];
int mn[n] = {};
for(int i=1; i<=m; i++){
int a, b; a = R[i-1][0], b = R[i-1][1];
vec[a].pb({b, i}); vec[b].pb({a, i});
if(mn[a] == 0) mn[a] = i;
if(mn[b] == 0) mn[b] = i;
}
int to[2*n] = {};
for(int a=0; a<n; a++){
auto [b, i] = vec[a][0];
if(mn[b] == i) to[a] = n+b;
else to[a] = b;
if(sz(vec[a]) >= 2){
auto [c, j] = vec[a][1];
if(mn[c] == j) to[n+a] = n+c;
else to[n+a] = c;
}
else{
if(mn[b] == i) to[n+a] = n+b;
else to[n+a] = b;
}
}
int succ[2*n][30] = {};
for(int a=0; a<2*n; a++){
succ[a][0] = to[a];
}
for(int i=1; i<30; i++){
for(int a=0; a<2*n; a++){
succ[a][i] = succ[succ[a][i-1]][i-1];
}
}
int p = P;
int q = Q;
int qry[q] = {};
for(int i=0; i<q; i++) qry[i] = G[i];
for(int i=0; i<q; i++){
int k = qry[i];
int ans = 0;
for(int a=0; a<n; a++){
int x = a;
for(int i=0; i<30; i++){
if(k & (1<<i)) x = succ[x][i];
}
if(x == p or x == n+p) ans++;
}
answer(ans);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
1 ms |
404 KB |
Output is correct |
8 |
Correct |
1 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
1 ms |
404 KB |
Output is correct |
8 |
Correct |
1 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
848 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
16 ms |
9532 KB |
Output is correct |
12 |
Correct |
37 ms |
14624 KB |
Output is correct |
13 |
Correct |
53 ms |
28576 KB |
Output is correct |
14 |
Correct |
106 ms |
45436 KB |
Output is correct |
15 |
Correct |
118 ms |
45128 KB |
Output is correct |
16 |
Correct |
88 ms |
32584 KB |
Output is correct |
17 |
Correct |
78 ms |
29164 KB |
Output is correct |
18 |
Correct |
46 ms |
14664 KB |
Output is correct |
19 |
Correct |
113 ms |
44416 KB |
Output is correct |
20 |
Correct |
110 ms |
45640 KB |
Output is correct |
21 |
Correct |
85 ms |
33472 KB |
Output is correct |
22 |
Correct |
85 ms |
28540 KB |
Output is correct |
23 |
Correct |
128 ms |
50248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
1 ms |
404 KB |
Output is correct |
8 |
Correct |
1 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
848 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
16 ms |
9532 KB |
Output is correct |
12 |
Correct |
37 ms |
14624 KB |
Output is correct |
13 |
Correct |
53 ms |
28576 KB |
Output is correct |
14 |
Correct |
106 ms |
45436 KB |
Output is correct |
15 |
Correct |
118 ms |
45128 KB |
Output is correct |
16 |
Correct |
88 ms |
32584 KB |
Output is correct |
17 |
Correct |
78 ms |
29164 KB |
Output is correct |
18 |
Correct |
46 ms |
14664 KB |
Output is correct |
19 |
Correct |
113 ms |
44416 KB |
Output is correct |
20 |
Correct |
110 ms |
45640 KB |
Output is correct |
21 |
Correct |
85 ms |
33472 KB |
Output is correct |
22 |
Correct |
85 ms |
28540 KB |
Output is correct |
23 |
Correct |
128 ms |
50248 KB |
Output is correct |
24 |
Correct |
8 ms |
336 KB |
Output is correct |
25 |
Correct |
2890 ms |
9756 KB |
Output is correct |
26 |
Execution timed out |
5052 ms |
14912 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |