#include "garden.h"
#include "gardenlib.h"
#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
long long counter = 0;
int tar;
vector<pair<int,int> > adj[150020];
void DFSVisit(int n, int hak, int road);
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
// printf("hebele\n");
tar = P;
for(int i=0; i<N; i++) {
int c1 = R[i][0];
int c2 = R[i][1];
// printf("hebele\n");
adj[c1].push_back(mp(c2,i));
adj[c2].push_back(mp(c1,i));
}
for(int test=0; test<Q;test++) {
counter =0;
for(int i=0; i<N; i++) DFSVisit(adj[i][0].first, G[test]-1, adj[i][0].second );
answer(counter);
}
}
void DFSVisit(int n, int hak, int road) {
// printf("%d\n", hak);
if(hak==0) {
if (n==tar) counter++;
return;
}
if(adj[n].size()==1) DFSVisit(adj[n][0].first, hak-1, road);
else if(adj[n][0].second != road) DFSVisit(adj[n][0].first, hak-1, adj[n][0].second);
else DFSVisit(adj[n][1].first, hak-1, adj[n][1].second);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3832 KB |
Output is correct |
2 |
Correct |
6 ms |
3960 KB |
Output is correct |
3 |
Correct |
6 ms |
3832 KB |
Output is correct |
4 |
Incorrect |
5 ms |
3876 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3832 KB |
Output is correct |
2 |
Correct |
6 ms |
3960 KB |
Output is correct |
3 |
Correct |
6 ms |
3832 KB |
Output is correct |
4 |
Incorrect |
5 ms |
3876 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3832 KB |
Output is correct |
2 |
Correct |
6 ms |
3960 KB |
Output is correct |
3 |
Correct |
6 ms |
3832 KB |
Output is correct |
4 |
Incorrect |
5 ms |
3876 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |