#include "garden.h"
#include "gardenlib.h"
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> v2i;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
#define pb push_back
#define mp make_pair
#define rept(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
int n, m, p, q;
vpi r;
vpi o; //outgoing trails from each fountain: best then second best
int k;
bool dfs(int u, int par = -2, int d = 0) {
if (d == k) return (u == p);
else {
int v;
if (o[u].first != p || o[u].second == -1) v = o[u].first;
else v = o[u].second;
return dfs(v, u, d + 1);
}
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
n = N, m = M, p = P, q = Q;
o.resize(N, { -1, -1 });
rep(i, M) {
int start = R[i][0], end = R[i][1];
r.pb({ start, end });
rep(j, 2) {
if (j == 1) swap(start, end);
if (o[start].first == -1) {
o[start].first = end;
}
else if (o[start].second == -1) {
o[start].second = end;
}
}
}
rep(i, Q) {
k = G[i];
int ans = 0;
rep(s, N) {
ans += dfs(s);
}
answer(ans);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |