#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
#define loop(i, a, b) for(int i = a; i <= b; i++)
#define loop_rev(i, a, b) for(int i = a; i >= b; i--)
#define all(x) x.begin(), x.end()
#define sz(x) int(x.size())
#define pb push_back
using ll = long long;
int n, m, p, q;
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
n = N, m = M, p = P, q = Q;
vector<vector<pair<int, int>>> graph(n);
loop(i, 0, m-1) {
graph[R[i][0]].pb({ i, R[i][1] });
graph[R[i][1]].pb({ i, R[i][0] });
}
loop(qi, 0, q-1) {
int k = G[qi];
vector<int> pr(n, (-1)), where(n);
iota(all(where), 0);
loop(phase, 1, k) {
loop(st_node, 0, n-1) {
pair<int, int> minim = { 1e9, 0 };
int i = where[st_node];
if(sz(graph[i]) == 1) {
minim = graph[i][0];
}
else {
for(auto [ prio, s ] : graph[i]) {
if(s == pr[st_node]) continue;
minim = min(minim, { prio, s });
}
}
where[st_node] = minim.second;
pr[st_node] = i;
}
}
int res = 0;
loop(i, 0, n-1) {
if(where[i] == p) {
++res;
}
}
answer(res);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |