Submission #1131607

#TimeUsernameProblemLanguageResultExecution timeMemory
1131607KodikRegions (IOI09_regions)C++20
0 / 100
89 ms196608 KiB
#include <bits/stdc++.h>
using namespace std;
#define ss second
#define ff first
typedef long long ll;
// #define int ll
const int MOD = 1e9+7;

const short int R = 25001;
int n, r, q;
vector<vector<int>> adj;
vector<short int> region;
vector<unsigned short int> active(R);
vector<vector<unsigned short int>> answer(R, vector<unsigned short int>(R));

void dfs(int node, int par){
    for(int i = 0; i <= r; ++i){
        // if(i==region[node]) continue;
        answer[region[node]][i] += active[i]; 
    }
    active[region[node]]++;
    for(int &c: adj[node]){
        if(c!=par){
            dfs(c, node);
        }
    }
    active[region[node]]--;
}


signed main() {
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);
    cin >> n >> r >> q;
    adj.resize(n); region.resize(n);
    cin >> region[0];
    for(int i = 1; i < n; ++i){
        int supervisor, home; cin >> supervisor >> home;
        adj[--supervisor].push_back(i);
        region[i] = home;
    }
    dfs(0, -1);
    for(int i = 0; i < q; ++i){
        int e1, e2; cin >> e1 >> e2;
        cout << answer[e2][e1] << endl;
    }
    return 0;
}  
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...