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>
#define mp make_pair
using namespace std;
long long counter = 0;
int tar;
vector< vector<pair<int,int> > > adj;
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;
adj.resize(N);
for(int test=0; test<Q;test++) {
counter =0;
//adj.clear();
// printf("hebele\n");
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));
}
// printf("hebele\n");
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |