This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "garden.h"
#include "gardenlib.h"
#include<bits/stdc++.h>
using namespace std;
int ans;
vector<int>adj[100001];
void dfs(int u,int p,int P,int G,int dis){
if(dis==G){
if(u==P)ans++;
return ;
}
if(adj[u][0]!=p||adj[u].size()==1)dfs(adj[u][0],u,P,G,dis+1);
else dfs(adj[u][1],u,P,G,dis+1);
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
for(int i=0; i<M; i++){
adj[R[i][0]].push_back(R[i][1]);
adj[R[i][1]].push_back(R[i][0]);
}
for(int i=0; i<Q; i++){
ans=0;
for(int u=0; u<N; u++){
dfs(u,-1,P,G[i],0);
}
answer(ans);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |