#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define sp <<" "<<
#define endl "\n"
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
vector<vector<int>> adj(N);
for (int i = 0; i < M; i++) {
auto [u, v] = R[i];
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int q = 0; q < Q; q++) {
int query = G[q];
int ans = 0;
for (int i = 0; i < N; i++) {
int last = -1;
int walk = 0;
int at = i;
// cerr << i << ": ";
while (walk < query) {
if (adj[at].size() >= 2 and adj[at][0] == last) {
last = at;
at = adj[at][1];
} else {
last = at;
at = adj[at][0];
}
// cerr << at << " ";
walk++;
}
if (at == P) ans++;
// cerr << "ans:" sp (at == P) << endl;
}
answer(ans);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |