Submission #511069

# Submission time Handle Problem Language Result Execution time Memory
511069 2022-01-15T05:18:27 Z tabr Tropical Garden (IOI11_garden) C++17
0 / 100
1 ms 460 KB
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

#include "garden.h"
#include "gardenlib.h"

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] + n;
        nxt[0][i + n] = (g[i].size() == 1 ? g[i][0] + n : g[i][1]);
    }
    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++;
            }
        }
        answer(ans);
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -