#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> h[150007],g[300007];
int d[2][300007],nxt[300007];
void dfs(int s,int k,int di)
{
if(d[k][s]!=-1)
{
d[k][s]=di;
return;
}
d[k][s]=di;
for(int i=0;i<g[s].size();i++) dfs(g[s][i],k,di+1);
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
int n=N;
for(int i=0;i<M;i++)
{
int p;
p=R[i][1];
h[R[i][0]].push_back(p);
p=R[i][0];
h[R[i][1]].push_back(p);
}
for(int i=0;i<N;i++)
{
if(h[h[i][0]][0]==i) nxt[i]=h[i][0]+n;
else nxt[i]=h[i][0];
if(h[i].size()>1)
{
if(h[h[i][1]][0]==i) nxt[i+n]=h[i][1]+n;
else nxt[i+n]=h[i][1];
}
else
{
if(h[h[i][0]][0]==i) nxt[i+n]=h[i][0]+n;
else nxt[i+n]=h[i][0];
}
d[0][i]=d[0][i+n]=d[1][i]=d[1][i+n]=-1;
}
for(int i=0;i<2*n;i++) g[nxt[i]].push_back(i);
dfs(P,0,0);
dfs(P+n,1,0);
for(int j=0;j<Q;j++)
{
int sol=0;
for(int i=0;i<N;i++) if(d[0][i]==G[j] || (d[0][i]>0 && d[0][P]>0 && d[0][i]<=G[j] && d[0][i]%d[0][P]==G[j]%d[0][P]) || d[1][i]==G[j] || (d[1][i]>0 && d[1][P+n]>0 && d[1][i]<=G[j] && d[1][i]%d[1][P+n]==G[j] % d[1][P+n])) sol++;
answer(sol);
}
}
Compilation message
garden.cpp: In function 'void dfs(int, int, int)':
garden.cpp:15:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<g[s].size();i++) dfs(g[s][i],k,di+1);
~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
11128 KB |
Output is correct |
2 |
Correct |
12 ms |
11020 KB |
Output is correct |
3 |
Correct |
13 ms |
11048 KB |
Output is correct |
4 |
Correct |
12 ms |
10872 KB |
Output is correct |
5 |
Correct |
11 ms |
10872 KB |
Output is correct |
6 |
Correct |
13 ms |
11128 KB |
Output is correct |
7 |
Correct |
12 ms |
10972 KB |
Output is correct |
8 |
Correct |
13 ms |
11000 KB |
Output is correct |
9 |
Correct |
15 ms |
11228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
11128 KB |
Output is correct |
2 |
Correct |
12 ms |
11020 KB |
Output is correct |
3 |
Correct |
13 ms |
11048 KB |
Output is correct |
4 |
Correct |
12 ms |
10872 KB |
Output is correct |
5 |
Correct |
11 ms |
10872 KB |
Output is correct |
6 |
Correct |
13 ms |
11128 KB |
Output is correct |
7 |
Correct |
12 ms |
10972 KB |
Output is correct |
8 |
Correct |
13 ms |
11000 KB |
Output is correct |
9 |
Correct |
15 ms |
11228 KB |
Output is correct |
10 |
Correct |
12 ms |
11000 KB |
Output is correct |
11 |
Correct |
26 ms |
13544 KB |
Output is correct |
12 |
Correct |
44 ms |
15024 KB |
Output is correct |
13 |
Correct |
71 ms |
29816 KB |
Output is correct |
14 |
Correct |
136 ms |
24312 KB |
Output is correct |
15 |
Correct |
182 ms |
24540 KB |
Output is correct |
16 |
Correct |
130 ms |
20752 KB |
Output is correct |
17 |
Correct |
121 ms |
19560 KB |
Output is correct |
18 |
Correct |
44 ms |
14840 KB |
Output is correct |
19 |
Correct |
136 ms |
24212 KB |
Output is correct |
20 |
Correct |
170 ms |
24324 KB |
Output is correct |
21 |
Correct |
128 ms |
20860 KB |
Output is correct |
22 |
Correct |
122 ms |
19432 KB |
Output is correct |
23 |
Correct |
143 ms |
25548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
11128 KB |
Output is correct |
2 |
Correct |
12 ms |
11020 KB |
Output is correct |
3 |
Correct |
13 ms |
11048 KB |
Output is correct |
4 |
Correct |
12 ms |
10872 KB |
Output is correct |
5 |
Correct |
11 ms |
10872 KB |
Output is correct |
6 |
Correct |
13 ms |
11128 KB |
Output is correct |
7 |
Correct |
12 ms |
10972 KB |
Output is correct |
8 |
Correct |
13 ms |
11000 KB |
Output is correct |
9 |
Correct |
15 ms |
11228 KB |
Output is correct |
10 |
Correct |
12 ms |
11000 KB |
Output is correct |
11 |
Correct |
26 ms |
13544 KB |
Output is correct |
12 |
Correct |
44 ms |
15024 KB |
Output is correct |
13 |
Correct |
71 ms |
29816 KB |
Output is correct |
14 |
Correct |
136 ms |
24312 KB |
Output is correct |
15 |
Correct |
182 ms |
24540 KB |
Output is correct |
16 |
Correct |
130 ms |
20752 KB |
Output is correct |
17 |
Correct |
121 ms |
19560 KB |
Output is correct |
18 |
Correct |
44 ms |
14840 KB |
Output is correct |
19 |
Correct |
136 ms |
24212 KB |
Output is correct |
20 |
Correct |
170 ms |
24324 KB |
Output is correct |
21 |
Correct |
128 ms |
20860 KB |
Output is correct |
22 |
Correct |
122 ms |
19432 KB |
Output is correct |
23 |
Correct |
143 ms |
25548 KB |
Output is correct |
24 |
Correct |
13 ms |
10972 KB |
Output is correct |
25 |
Correct |
151 ms |
13640 KB |
Output is correct |
26 |
Correct |
184 ms |
15352 KB |
Output is correct |
27 |
Correct |
2932 ms |
30156 KB |
Output is correct |
28 |
Correct |
1677 ms |
24716 KB |
Output is correct |
29 |
Correct |
3071 ms |
24708 KB |
Output is correct |
30 |
Correct |
1861 ms |
20956 KB |
Output is correct |
31 |
Correct |
1599 ms |
19504 KB |
Output is correct |
32 |
Correct |
191 ms |
14940 KB |
Output is correct |
33 |
Correct |
1699 ms |
24184 KB |
Output is correct |
34 |
Correct |
2996 ms |
24440 KB |
Output is correct |
35 |
Correct |
1831 ms |
20728 KB |
Output is correct |
36 |
Correct |
2209 ms |
19508 KB |
Output is correct |
37 |
Correct |
1196 ms |
25528 KB |
Output is correct |
38 |
Correct |
4054 ms |
36788 KB |
Output is correct |