This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "garden.h"
#include "gardenlib.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
const int NN = (int)150007;
int deg[NN];
int n, m, p, q;
vector < int > gr[NN];
int K;
int solve(int v) {
int k = K;
int pr = v;
while (k--) {
if (gr[v][0] == pr) {
if (gr[v].size() > 1) {
pr = v;
v = gr[v][1];
} else {
pr = v;
v = gr[v][0];
}
} else {
pr = v;
v = gr[v][0];
}
}
return v == p;
}
void count_routes(int _N, int _M, int _P, int R[][2], int _Q, int G[]) {
n = _N; m = _M; p = _P;
for (int i = 0; i < m; i++) {
if (deg[R[i][0]] != 2) {
gr[R[i][0]].push_back(R[i][1]);
deg[R[i][0]]++;
}
if (deg[R[i][1]] != 2) {
gr[R[i][1]].push_back(R[i][0]);
deg[R[i][1]]++;
}
}
for (int j = 0; j < _Q; j++) {
int ans = 0;
K = G[j];
for (int i = 0; i < n; i++) {
ans += solve(i);
}
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... |