# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
410856 | LouayFarah | Tropical Garden (IOI11_garden) | C++14 | 0 ms | 0 KiB |
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 <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 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);
}
}