Submission #1062982

#TimeUsernameProblemLanguageResultExecution timeMemory
1062982BoasTropical Garden (IOI11_garden)C++17
0 / 100
1 ms604 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<bool> vb; typedef vector<ii> vii; typedef vector<vi> vvi; typedef vector<vb> vvb; 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(N)); vvb otherOption(30, vb(N)); loop(N, i) { auto [j, ix] = adj[i][0]; p[0][i] = j; if (adj[j][0] == ii{i, ix}) otherOption[0][i] = 1; } auto nthParent = [&](auto &&self, int i, int n) -> int { loop(30, x) { if ((1 << x) & n) { if (otherOption[x][i] && adj[i].size() > 1) { i = self(self, adj[i][1].second, (1 << x) - 1); } else i = p[x][i]; } } return i; }; for (int x = 1; x < 30; x++) { loop(N, i) { int half = p[x - 1][i]; if (otherOption[x - 1][i] && adj[i].size() > 1) { half = nthParent(nthParent, adj[i][1].second, (1 << (x - 1)) - 1); } int nieuw = p[x - 1][half]; if (otherOption[x - 1][half] && adj[half].size() > 1) { nieuw = nthParent(nthParent, adj[half][1].second, (1 << (x - 1)) - 1); } p[x][i] = nieuw; } } for (int i = 0; i < Q; i++) { int K = G[i]; int cnt = 0; loop(N, start) { if (nthParent(nthParent, start, K) == P) cnt++; } answer(cnt); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...