Submission #511076

#TimeUsernameProblemLanguageResultExecution timeMemory
511076tabrTropical Garden (IOI11_garden)C++17
69 / 100
5060 ms47912 KiB
#include <bits/stdc++.h> using namespace std; #ifdef tabr #include "library/debug.cpp" #else #define debug(...) #endif #ifdef tabr void answer(int n) { cout << n << '\n'; } #else #include "garden.h" #include "gardenlib.h" #endif void count_routes(int n, int m, int p, int r[][2], int q, int k[]) { vector<vector<int>> g(n); for (int i = 0; i < m; i++) { g[r[i][0]].emplace_back(r[i][1]); g[r[i][1]].emplace_back(r[i][0]); } vector<vector<int>> nxt(30, vector<int>(2 * n)); for (int i = 0; i < n; i++) { nxt[0][i] = g[i][0]; nxt[0][i + n] = (g[i].size() == 1 ? g[i][0] : g[i][1]); if (g[nxt[0][i]][0] == i) { nxt[0][i] += n; } if (g[nxt[0][i + n]][0] == i) { nxt[0][i + n] += n; } } for (int i = 1; i < 30; i++) { for (int j = 0; j < 2 * n; j++) { nxt[i][j] = nxt[i - 1][nxt[i - 1][j]]; } } for (int i = 0; i < q; i++) { int ans = 0; for (int j = 0; j < n; j++) { int v = j; for (int l = 29; l >= 0; l--) { if (k[i] & (1 << l)) { v = nxt[l][v]; } } if (v % n == p) { ans++; } debug(v, j); } answer(ans); } } #ifdef tabr int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, p, q; cin >> n >> m >> p >> q; int r[100][2]; int k[100]; for (int i = 0; i < m; i++) { cin >> r[i][0] >> r[i][1]; } for (int i = 0; i < q; i++) { cin >> k[i]; } count_routes(n, m, p, r, q, k); return 0; } #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...