#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define se second
#define sz(a) (int)a.size()
const int mxN = (int)3e5+10;
int n, m, t;
bool vis[2][mxN];
vector<int> adj[mxN];
int mov[2][mxN], dis[2][mxN], c[2];
vector<pair<int,int>> adj2[mxN];
void dfs(int s, int i, int dep=0){
dis[i][s] = dep; vis[i][s] = 1;
for(auto u : adj[s]){
if(u==i*n+t) c[i] = dep+1;
if(!vis[i][u]) dfs(u,i,dep+1);
}
}
void count_routes(int N, int M, int P, int R[][2], int q, int G[]){
n = N, m = M; t = P;
memset(dis,-1,sizeof(dis)); c[0]=c[1]=-1;
for(int i = 0; i < m; i++){
adj2[R[i][0]].pb({i,R[i][1]});
adj2[R[i][1]].pb({i,R[i][0]});
}
for(int i = 0; i < n; i++){
sort(begin(adj2[i]),end(adj2[i]));
mov[0][i] = adj2[i][0].se;
mov[1][i] = adj2[i][sz(adj2[i])>1].se;
}
for(int i = 0; i < n; i++){
bool ok = (i==mov[0][mov[0][i]]);
adj[n*ok+mov[0][i]].pb(i);
ok = (i==mov[0][mov[1][i]]);
adj[n*ok+mov[1][i]].pb(n+i);
}
dfs(t,0); dfs(n+t,1);
for(int i = 0; i < q; i++){
int k = G[i], tot = 0;
for(int j = 0; j < n; j++){
for(int l = 0; l < 2; l++){
bool ok = 1;
if(dis[l][j]==-1) ok=0;
else if(c[l]==-1) ok = (dis[l][j]==k);
else{
int rem = k-dis[l][j];
ok = (rem%c[l]==0 and rem>=0);
}
if(ok) {tot++; break;}
}
}
answer(tot);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
16852 KB |
Output is correct |
2 |
Correct |
8 ms |
16848 KB |
Output is correct |
3 |
Correct |
8 ms |
16852 KB |
Output is correct |
4 |
Correct |
8 ms |
16724 KB |
Output is correct |
5 |
Correct |
8 ms |
16712 KB |
Output is correct |
6 |
Correct |
9 ms |
16980 KB |
Output is correct |
7 |
Correct |
8 ms |
16716 KB |
Output is correct |
8 |
Correct |
8 ms |
16848 KB |
Output is correct |
9 |
Correct |
10 ms |
17132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
16852 KB |
Output is correct |
2 |
Correct |
8 ms |
16848 KB |
Output is correct |
3 |
Correct |
8 ms |
16852 KB |
Output is correct |
4 |
Correct |
8 ms |
16724 KB |
Output is correct |
5 |
Correct |
8 ms |
16712 KB |
Output is correct |
6 |
Correct |
9 ms |
16980 KB |
Output is correct |
7 |
Correct |
8 ms |
16716 KB |
Output is correct |
8 |
Correct |
8 ms |
16848 KB |
Output is correct |
9 |
Correct |
10 ms |
17132 KB |
Output is correct |
10 |
Correct |
8 ms |
16724 KB |
Output is correct |
11 |
Correct |
19 ms |
19160 KB |
Output is correct |
12 |
Correct |
30 ms |
21048 KB |
Output is correct |
13 |
Correct |
46 ms |
37964 KB |
Output is correct |
14 |
Correct |
89 ms |
30776 KB |
Output is correct |
15 |
Correct |
129 ms |
31092 KB |
Output is correct |
16 |
Correct |
97 ms |
28100 KB |
Output is correct |
17 |
Correct |
83 ms |
27184 KB |
Output is correct |
18 |
Correct |
30 ms |
21132 KB |
Output is correct |
19 |
Correct |
83 ms |
30796 KB |
Output is correct |
20 |
Correct |
114 ms |
31080 KB |
Output is correct |
21 |
Correct |
95 ms |
27836 KB |
Output is correct |
22 |
Correct |
78 ms |
27096 KB |
Output is correct |
23 |
Correct |
102 ms |
31900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
16852 KB |
Output is correct |
2 |
Correct |
8 ms |
16848 KB |
Output is correct |
3 |
Correct |
8 ms |
16852 KB |
Output is correct |
4 |
Correct |
8 ms |
16724 KB |
Output is correct |
5 |
Correct |
8 ms |
16712 KB |
Output is correct |
6 |
Correct |
9 ms |
16980 KB |
Output is correct |
7 |
Correct |
8 ms |
16716 KB |
Output is correct |
8 |
Correct |
8 ms |
16848 KB |
Output is correct |
9 |
Correct |
10 ms |
17132 KB |
Output is correct |
10 |
Correct |
8 ms |
16724 KB |
Output is correct |
11 |
Correct |
19 ms |
19160 KB |
Output is correct |
12 |
Correct |
30 ms |
21048 KB |
Output is correct |
13 |
Correct |
46 ms |
37964 KB |
Output is correct |
14 |
Correct |
89 ms |
30776 KB |
Output is correct |
15 |
Correct |
129 ms |
31092 KB |
Output is correct |
16 |
Correct |
97 ms |
28100 KB |
Output is correct |
17 |
Correct |
83 ms |
27184 KB |
Output is correct |
18 |
Correct |
30 ms |
21132 KB |
Output is correct |
19 |
Correct |
83 ms |
30796 KB |
Output is correct |
20 |
Correct |
114 ms |
31080 KB |
Output is correct |
21 |
Correct |
95 ms |
27836 KB |
Output is correct |
22 |
Correct |
78 ms |
27096 KB |
Output is correct |
23 |
Correct |
102 ms |
31900 KB |
Output is correct |
24 |
Correct |
10 ms |
16724 KB |
Output is correct |
25 |
Correct |
163 ms |
19252 KB |
Output is correct |
26 |
Correct |
241 ms |
21180 KB |
Output is correct |
27 |
Correct |
2194 ms |
37988 KB |
Output is correct |
28 |
Correct |
1279 ms |
30852 KB |
Output is correct |
29 |
Correct |
2498 ms |
31216 KB |
Output is correct |
30 |
Correct |
1424 ms |
28240 KB |
Output is correct |
31 |
Correct |
1464 ms |
27208 KB |
Output is correct |
32 |
Correct |
255 ms |
21172 KB |
Output is correct |
33 |
Correct |
1352 ms |
30924 KB |
Output is correct |
34 |
Correct |
2645 ms |
31200 KB |
Output is correct |
35 |
Correct |
1598 ms |
28056 KB |
Output is correct |
36 |
Correct |
1533 ms |
27168 KB |
Output is correct |
37 |
Correct |
1271 ms |
31928 KB |
Output is correct |
38 |
Correct |
2082 ms |
45132 KB |
Output is correct |