# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1137235 | mrsmartypants | Tropical Garden (IOI11_garden) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#include <vector>
#include "garden.h"
#include "gardenlib.h"
using namespace std;
void count_routes(int N, int M, int P, int R[][2], int Q, int G) {
vector<int> ans(Q);
vector<vector<int>> g(N, vector<int>(0));
for (int i = 0; i < M; i++) {
g[R[i][0]].push_back(R[i][1]);
g[R[i][1]].push_back(R[i][0]);
}
vector<vector<int>> DP(N, vector<int>(2, -1));
int timer = -1;
int cycSz = -1;
auto dfs = [&](auto self, int node, int prevNode) -> void
{
timer++;
int state = 0, nextNode = g[node][0];
if (g[node][0] == prevNode && g[node].size() >= 2) {
state = 1;
nextNode = g[node][1];
}
if (DP[node][state] != -1) {
if (node == P) cycSz = timer - DP[node][state];