#include <bits/stdc++.h>
#include "garden.h"
using namespace std;
void dfs(vector<int> adj[], int u, int p, int k, int parent, int &res)
{
if(k==0)
{
if(u==p)
res++;
return;
}
if(adj[u].size()==1)
dfs(adj, adj[u][0], p, k-1, u, res);
else if(adj[u].size()>1)
{
if(adj[u][0]==parent)
dfs(adj, adj[u][1], p, k-1, u, res);
else
dfs(adj, adj[u][0], p, k-1, u, res);
}
}
void answer(int x);
void count_routes(int n, int m, int p, int r[][2], int q, int g[])
{
vector<int> adj[n];
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 querie = 0; querie<q; querie++)
{
int k = g[querie];
int res = 0;
for(int u = 0; u<n; u++)
{
if(u==p)
continue;
dfs(adj, u, p, k, -1, res);
}
answer(res);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |