제출 #1063220

#제출 시각아이디문제언어결과실행 시간메모리
1063220Boas열대 식물원 (Tropical Garden) (IOI11_garden)C++17
0 / 100
1 ms860 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...