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 "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define loop(x, i) for (int i = 0; i < x; i++)
#define pb push_back
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
vvii adj(N);
loop(M, i)
{
adj[R[i][0]].pb({i, R[i][1]});
adj[R[i][1]].pb({i, R[i][0]});
}
vvi p(30, vi(2 * N));
loop(N, i)
{
int j = adj[i][0].second;
if (adj[j][0].second == i)
j += N;
p[0][i] = j;
if (adj[i].size() == 1)
{
p[0][i + N] = j;
}
else
{
int j = adj[i][1].second;
if (adj[j][0].second == i)
j += N;
p[0][i + N] = j;
}
}
loop(30, x)
{
loop(N, i)
{
int half = p[x - 1][i];
p[x][i] = p[x - 1][half];
}
}
auto nthParent = [&](auto &&self, int i, int n) -> int
{
loop(30, x)
{
if ((1 << x) & n)
{
i = p[x][i];
}
}
return i;
};
for (int i = 0; i < Q; i++)
{
int K = G[i];
int cnt = 0;
loop(N, start)
{
if (nthParent(nthParent, start, K) % N == P)
cnt++;
}
answer(cnt);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |