#include "garden.h"
#include "gardenlib.h"
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
const int MAX_N = 2*1e5;
pii bl[2*MAX_N][30];
int max_p[MAX_N];
int to_id(pii pos){
return pos.first*MAX_N+ pos.second;
}
vector<vector<pii>> adj;
int get_step(int id, int d){
int cur = id;
for(int i = 0; i<30; i++){
if((d& (1<<i)) != 0){
if(bl[cur][i].first == max_p[bl[cur][i].second]){
cur = bl[cur][i].second + MAX_N;
}
else{
cur = bl[cur][i].second;
}
}
}
return cur;
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
adj.resize(N);
for(int i = 0; i <M; i++){
adj[R[i][0]].push_back(pii(i, R[i][1]));
adj[R[i][1]].push_back(pii(i, R[i][0]));
}
for(int i = 0; i<N; i++){
bl[i][0] = adj[i][0];
max_p[i] = adj[i][0].first;
if(adj[i].size()>1){
bl[i+MAX_N][0] = adj[i][1];
}
else{
bl[i+MAX_N][0] = adj[i][0];
}
}
for(int i = 1; i<30; i++){
for(int j = 0; j<N; j++){
if(bl[j][i-1].first == max_p[bl[j][i-1].second]){
bl[j][i] = bl[bl[j][i-1].second + MAX_N][i-1];
}
else{
bl[j][i] = bl[bl[j][i-1].second][i-1];
}
}
for(int j = 0; j<N+MAX_N; j++){
if(bl[j][i-1].first == max_p[bl[j][i-1].second]){
bl[j][i] = bl[bl[j][i-1].second + MAX_N][i-1];
}
else{
bl[j][i] = bl[bl[j][i-1].second][i-1];
}
}
}
for(int i = 0; i<Q; i++){
int res= 0;
for(int j = 0; j<N; j++){
if(get_step(j, G[i])%MAX_N == P){
res++;
}
}
answer(res);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
51776 KB |
Output is correct |
2 |
Correct |
64 ms |
51788 KB |
Output is correct |
3 |
Correct |
69 ms |
51800 KB |
Output is correct |
4 |
Correct |
72 ms |
51548 KB |
Output is correct |
5 |
Correct |
57 ms |
51560 KB |
Output is correct |
6 |
Correct |
78 ms |
51844 KB |
Output is correct |
7 |
Correct |
62 ms |
51548 KB |
Output is correct |
8 |
Correct |
62 ms |
51804 KB |
Output is correct |
9 |
Correct |
64 ms |
52060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
51776 KB |
Output is correct |
2 |
Correct |
64 ms |
51788 KB |
Output is correct |
3 |
Correct |
69 ms |
51800 KB |
Output is correct |
4 |
Correct |
72 ms |
51548 KB |
Output is correct |
5 |
Correct |
57 ms |
51560 KB |
Output is correct |
6 |
Correct |
78 ms |
51844 KB |
Output is correct |
7 |
Correct |
62 ms |
51548 KB |
Output is correct |
8 |
Correct |
62 ms |
51804 KB |
Output is correct |
9 |
Correct |
64 ms |
52060 KB |
Output is correct |
10 |
Correct |
62 ms |
51616 KB |
Output is correct |
11 |
Correct |
72 ms |
57424 KB |
Output is correct |
12 |
Correct |
104 ms |
63376 KB |
Output is correct |
13 |
Correct |
153 ms |
75860 KB |
Output is correct |
14 |
Correct |
189 ms |
92792 KB |
Output is correct |
15 |
Correct |
183 ms |
93008 KB |
Output is correct |
16 |
Correct |
140 ms |
80836 KB |
Output is correct |
17 |
Correct |
156 ms |
76112 KB |
Output is correct |
18 |
Correct |
96 ms |
63172 KB |
Output is correct |
19 |
Correct |
173 ms |
92784 KB |
Output is correct |
20 |
Correct |
177 ms |
92968 KB |
Output is correct |
21 |
Correct |
148 ms |
80748 KB |
Output is correct |
22 |
Correct |
155 ms |
75920 KB |
Output is correct |
23 |
Correct |
187 ms |
97692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
51776 KB |
Output is correct |
2 |
Correct |
64 ms |
51788 KB |
Output is correct |
3 |
Correct |
69 ms |
51800 KB |
Output is correct |
4 |
Correct |
72 ms |
51548 KB |
Output is correct |
5 |
Correct |
57 ms |
51560 KB |
Output is correct |
6 |
Correct |
78 ms |
51844 KB |
Output is correct |
7 |
Correct |
62 ms |
51548 KB |
Output is correct |
8 |
Correct |
62 ms |
51804 KB |
Output is correct |
9 |
Correct |
64 ms |
52060 KB |
Output is correct |
10 |
Correct |
62 ms |
51616 KB |
Output is correct |
11 |
Correct |
72 ms |
57424 KB |
Output is correct |
12 |
Correct |
104 ms |
63376 KB |
Output is correct |
13 |
Correct |
153 ms |
75860 KB |
Output is correct |
14 |
Correct |
189 ms |
92792 KB |
Output is correct |
15 |
Correct |
183 ms |
93008 KB |
Output is correct |
16 |
Correct |
140 ms |
80836 KB |
Output is correct |
17 |
Correct |
156 ms |
76112 KB |
Output is correct |
18 |
Correct |
96 ms |
63172 KB |
Output is correct |
19 |
Correct |
173 ms |
92784 KB |
Output is correct |
20 |
Correct |
177 ms |
92968 KB |
Output is correct |
21 |
Correct |
148 ms |
80748 KB |
Output is correct |
22 |
Correct |
155 ms |
75920 KB |
Output is correct |
23 |
Correct |
187 ms |
97692 KB |
Output is correct |
24 |
Correct |
61 ms |
51736 KB |
Output is correct |
25 |
Correct |
3911 ms |
57508 KB |
Output is correct |
26 |
Execution timed out |
5038 ms |
63380 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |