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>
#define s second
#define f first
#include "garden.h"
#include "gardenlib.h"
using namespace std;
const int N = 1005;
int K,P,ans=0;
vector<pair<int,int> > A[N];
void dfs(int u,int k, int par = -1) {
if(k==K) {
// cout << "can\n";
if(u==P)ans++;
return;
}
if(A[u].size() == 1) dfs(A[u][0].s,k+1,u);
else for(auto [w,nxt] : A[u]) if(nxt!=par) {
dfs(nxt,k+1,u);
break;
}
}
void count_routes(int n, int m, int pp, int R[][2], int Q, int G[])
{
K = G[0];
P = pp;
for(int i = 0;i<m;i++) {
A[R[i][0]].push_back({i,R[i][1]});
A[R[i][1]].push_back({i,R[i][0]});
}
for(int i = 0;i<n;i++) sort(A[i].begin(),A[i].end());
for(int i = 0;i<n;i++){
// cout << "doing " << i << "\n";
dfs(i,0);
}
answer(ans);
}
/*
/usr/bin/g++ -DEVAL -std=gnu++11 -O2 -pipe -s -o garden grader.cpp garden.cpp
./garden
6 6 0
1 2
0 1
0 3
3 4
4 5
1 5
1
3
2
5 5 2
1 0
1 2
3 2
1 3
4 2
2
3 1
1 2
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |