Submission #913904

# Submission time Handle Problem Language Result Execution time Memory
913904 2024-01-20T13:13:34 Z VMaksimoski008 Regions (IOI09_regions) C++14
17 / 100
1370 ms 131072 KB
#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define rall(x) x.rbegin(), x.rend()
//#define int long long

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 2e5 + 5;
const double eps = 1e-9;

void setIO() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int n, r, q, home[maxn+1], dp[501][maxn];
vector<vector<int> > graph;

void dfs(int u, int p) {
    dp[home[u]][u]++;

    for(int &v : graph[u]) {
        if(v == p) continue;
        dfs(v, u);
        for(int i=1; i<=r; i++)
            dp[i][u] += dp[i][v];
    }
}

int32_t main() {
    setIO();

    cin >> n >> r >> q;
    graph.resize(n+1);

    cin >> home[1];

    for(int i=2; i<=n; i++) {
        int p;
        cin >> p >> home[i];
        graph[i].push_back(p);
        graph[p].push_back(i);
    }

    if(r <= 500) {
        dfs(1, 0);
        vector<vector<int> > by_home(r+1);
        for(int i=1; i<=n; i++) by_home[home[i]].push_back(i);

        while(q--) {
            int r1, r2, ans = 0;
            cin >> r1 >> r2;

            for(int &x : by_home[r1])
                ans += dp[r2][x];
        
            cout << ans << '\n';
            cout.flush();
        }
    }


    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 2 ms 10584 KB Output is correct
4 Correct 5 ms 16728 KB Output is correct
5 Correct 6 ms 25336 KB Output is correct
6 Correct 30 ms 130392 KB Output is correct
7 Correct 20 ms 22360 KB Output is correct
8 Correct 29 ms 81752 KB Output is correct
9 Runtime error 24 ms 131072 KB Execution killed with signal 9
10 Correct 73 ms 48892 KB Output is correct
11 Correct 83 ms 54536 KB Output is correct
12 Runtime error 27 ms 131072 KB Execution killed with signal 9
13 Correct 187 ms 93008 KB Output is correct
14 Correct 124 ms 45888 KB Output is correct
15 Runtime error 32 ms 131072 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 39 ms 131072 KB Execution killed with signal 9
2 Correct 1370 ms 105876 KB Output is correct
3 Runtime error 43 ms 131072 KB Execution killed with signal 9
4 Incorrect 7 ms 2108 KB Unexpected end of file - int32 expected
5 Incorrect 9 ms 2528 KB Unexpected end of file - int32 expected
6 Incorrect 10 ms 3700 KB Unexpected end of file - int32 expected
7 Incorrect 14 ms 4520 KB Unexpected end of file - int32 expected
8 Incorrect 20 ms 6320 KB Unexpected end of file - int32 expected
9 Incorrect 36 ms 9224 KB Unexpected end of file - int32 expected
10 Incorrect 37 ms 10432 KB Unexpected end of file - int32 expected
11 Incorrect 44 ms 12592 KB Unexpected end of file - int32 expected
12 Incorrect 48 ms 11564 KB Unexpected end of file - int32 expected
13 Incorrect 47 ms 12044 KB Unexpected end of file - int32 expected
14 Incorrect 48 ms 12196 KB Unexpected end of file - int32 expected
15 Incorrect 40 ms 12052 KB Unexpected end of file - int32 expected
16 Incorrect 41 ms 12148 KB Unexpected end of file - int32 expected
17 Incorrect 47 ms 12224 KB Unexpected end of file - int32 expected