이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "garden.h"
#include "gardenlib.h"
using namespace std;
const int maxn = 1e3+10;
const int maxm = 2e4+10;
typedef pair<int, int> pii;
int m, p, k;
bool mark[maxm], ok;
vector<pii> grafo[maxn];
void dfs(int u, int ant, int qtd)
{
if (u == p && qtd == k)
{
ok = 1;
return;
}
for (auto pp: grafo[u])
{
int v = pp.first, e = pp.second;
if (mark[e]) continue;
if (grafo[v].size() > 1 && abs(e-ant) == m) continue;
mark[e] = true;
dfs(v, e, qtd+1);
}
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
for (int i = 0; i < M; i++)
{
int u = R[i][0], v = R[i][1];
grafo[u].push_back({v, i}); grafo[v].push_back({u, i+M});
}
m = M, p = P, k = G[0];
int ans = 0;
for (int i = 0; i < N; i++)
{
ok = 0;
memset(mark, 0, sizeof mark);
dfs(i, -1, 0);
if (ok) ans++;
}
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... |