#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#include "garden.h"
#include "gardenlib.h"
const int N=1e6+99,inf=1e9+99;
int n,m,s,a[N][2],b[N],p[N],vis[N],dist0[N],dist1[N];
vector<int> g[N],adj[N];
void dfs0(int u){
dist0[u]=inf;
vis[u]=1;
if(u==(s<<1)){
dist0[u]=0;
return ;
}
if(vis[p[u]]==0) dfs0(p[u]);
dist0[u]=dist0[p[u]]+1;
}
void dfs1(int u){
dist1[u]=inf;
vis[u]=1;
if(u==(s<<1|1)){
dist1[u]=0;
return ;
}
if(vis[p[u]]==0) dfs1(p[u]);
dist1[u]=dist1[p[u]]+1;
}
void count_routes(int _n, int _m, int _s, int R[][2], int Q, int G[]){
n=_n,m=_m,s=_s;
f(i,0,m){
int u=R[i][0],v=R[i][1];
if(g[u].size()<2) adj[u].pb(v);
if(g[v].size()<2) adj[v].pb(u);
}
f(i,0,n){
p[i<<1]=(adj[i][0]<<1)+(adj[adj[i][0]][0]==i ? 1 : 0);
if(adj[i].size()<2) p[i<<1|1]=p[i<<1];
else{
p[i<<1|1]=(adj[i][1]<<1)+(adj[adj[i][1]][0]==i ? 1 : 0);
}
}
f(i,0,n<<1) if(!vis[i]) dfs0(i);
fill(vis,vis+N,0);
f(i,0,n<<1) if(!vis[i]) dfs1(i);
int u,len0=0,len1=0;
fill(vis,vis+N,0);
u=s<<1;
while(1){
vis[u]=1;
len0++;
if(vis[p[u]]) break;
u=p[u];
}
if(p[u]!=(s<<1)) len0=inf;
fill(vis,vis+N,0);
u=s<<1|1;
while(1){
vis[u]=1;
len1++;
if(vis[p[u]]) break;
u=p[u];
}
if(p[u]!=(s<<1|1)) len1=inf;
f(i,0,Q){
int k=G[i],res=0;
f(i,0,n){
if((dist0[i<<1]<=k && (k-dist0[i<<1])%len0==0) || (dist1[i<<1]<=k && (k-dist1[i<<1])%len1==0)){
res++;
}
}
answer(res);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
51284 KB |
Output is correct |
2 |
Correct |
25 ms |
51220 KB |
Output is correct |
3 |
Correct |
27 ms |
51248 KB |
Output is correct |
4 |
Correct |
24 ms |
51120 KB |
Output is correct |
5 |
Correct |
23 ms |
51168 KB |
Output is correct |
6 |
Correct |
25 ms |
51348 KB |
Output is correct |
7 |
Correct |
26 ms |
51176 KB |
Output is correct |
8 |
Correct |
25 ms |
51284 KB |
Output is correct |
9 |
Correct |
27 ms |
51468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
51284 KB |
Output is correct |
2 |
Correct |
25 ms |
51220 KB |
Output is correct |
3 |
Correct |
27 ms |
51248 KB |
Output is correct |
4 |
Correct |
24 ms |
51120 KB |
Output is correct |
5 |
Correct |
23 ms |
51168 KB |
Output is correct |
6 |
Correct |
25 ms |
51348 KB |
Output is correct |
7 |
Correct |
26 ms |
51176 KB |
Output is correct |
8 |
Correct |
25 ms |
51284 KB |
Output is correct |
9 |
Correct |
27 ms |
51468 KB |
Output is correct |
10 |
Correct |
26 ms |
51204 KB |
Output is correct |
11 |
Correct |
31 ms |
52764 KB |
Output is correct |
12 |
Correct |
44 ms |
54016 KB |
Output is correct |
13 |
Correct |
58 ms |
61796 KB |
Output is correct |
14 |
Correct |
91 ms |
59924 KB |
Output is correct |
15 |
Correct |
90 ms |
60064 KB |
Output is correct |
16 |
Correct |
82 ms |
57896 KB |
Output is correct |
17 |
Correct |
77 ms |
57096 KB |
Output is correct |
18 |
Correct |
44 ms |
53748 KB |
Output is correct |
19 |
Correct |
85 ms |
59816 KB |
Output is correct |
20 |
Correct |
90 ms |
60088 KB |
Output is correct |
21 |
Correct |
77 ms |
57740 KB |
Output is correct |
22 |
Correct |
75 ms |
57016 KB |
Output is correct |
23 |
Correct |
94 ms |
60992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
51284 KB |
Output is correct |
2 |
Correct |
25 ms |
51220 KB |
Output is correct |
3 |
Correct |
27 ms |
51248 KB |
Output is correct |
4 |
Correct |
24 ms |
51120 KB |
Output is correct |
5 |
Correct |
23 ms |
51168 KB |
Output is correct |
6 |
Correct |
25 ms |
51348 KB |
Output is correct |
7 |
Correct |
26 ms |
51176 KB |
Output is correct |
8 |
Correct |
25 ms |
51284 KB |
Output is correct |
9 |
Correct |
27 ms |
51468 KB |
Output is correct |
10 |
Correct |
26 ms |
51204 KB |
Output is correct |
11 |
Correct |
31 ms |
52764 KB |
Output is correct |
12 |
Correct |
44 ms |
54016 KB |
Output is correct |
13 |
Correct |
58 ms |
61796 KB |
Output is correct |
14 |
Correct |
91 ms |
59924 KB |
Output is correct |
15 |
Correct |
90 ms |
60064 KB |
Output is correct |
16 |
Correct |
82 ms |
57896 KB |
Output is correct |
17 |
Correct |
77 ms |
57096 KB |
Output is correct |
18 |
Correct |
44 ms |
53748 KB |
Output is correct |
19 |
Correct |
85 ms |
59816 KB |
Output is correct |
20 |
Correct |
90 ms |
60088 KB |
Output is correct |
21 |
Correct |
77 ms |
57740 KB |
Output is correct |
22 |
Correct |
75 ms |
57016 KB |
Output is correct |
23 |
Correct |
94 ms |
60992 KB |
Output is correct |
24 |
Correct |
26 ms |
51152 KB |
Output is correct |
25 |
Correct |
105 ms |
52792 KB |
Output is correct |
26 |
Correct |
138 ms |
53960 KB |
Output is correct |
27 |
Correct |
2233 ms |
61896 KB |
Output is correct |
28 |
Correct |
839 ms |
59944 KB |
Output is correct |
29 |
Correct |
2521 ms |
60176 KB |
Output is correct |
30 |
Correct |
1440 ms |
57912 KB |
Output is correct |
31 |
Correct |
1447 ms |
57236 KB |
Output is correct |
32 |
Correct |
151 ms |
53864 KB |
Output is correct |
33 |
Correct |
830 ms |
59932 KB |
Output is correct |
34 |
Correct |
2537 ms |
60220 KB |
Output is correct |
35 |
Correct |
1506 ms |
57792 KB |
Output is correct |
36 |
Correct |
1719 ms |
57120 KB |
Output is correct |
37 |
Correct |
640 ms |
61004 KB |
Output is correct |
38 |
Correct |
1982 ms |
65440 KB |
Output is correct |