Submission #1292086

#TimeUsernameProblemLanguageResultExecution timeMemory
1292086qrnRegions (IOI09_regions)C++20
0 / 100
1367 ms196608 KiB
// ome47
// booooooo
#include "bits/stdc++.h"
using namespace std;
#define intt long long

const intt mxN = 2e5 + 5;
const intt LG = 20;
const intt inf = 1e18;

intt n, r, q;
vector<vector<intt>> graph, boo;
vector<intt> h(mxN), par(mxN);
map<intt,intt>mp[501];

void dfs(intt node, intt parent) {
    for(auto u : graph[node]) {
        if(u != parent) {
            dfs(u, node);
            for(auto p : mp[h[u]]) {
                mp[h[node]][p.first] += p.second;
                // cout << "AFTER " << node << " " << u << endl;
                // for(intt i = 1; i <= n; i++) {
                //     cout << i << ": ";
                //     for(auto p : mp[i]) {
                //         cout << "{" << p.first << ", " << p.second << "} ";
                //     }
                //     cout << endl;
                // }
            }
        }
    }
}

void _() {
    cin >> n >> r >> q;
    graph.assign(n + 1, vector<intt> {});
    boo.assign(r + 1, vector<intt>(r + 1, 0ll));

    for(intt i = 1; i <= n; i++) {
        intt supervisor, race;
        if(i == 1) {
            cin >> race;
        } else {
            cin >> supervisor >> race;
            graph[supervisor].push_back(i);
            graph[i].push_back(supervisor);
        }
        h[i] = race;
    }
    for(intt i = 1; i <= n; i++) {
        mp[h[i]][h[i]]=1;
    }

    dfs(1, 1);
    // cout << "ASDSAD" << endl;

    
    while(q--) {
        intt a, b;
        cin >> a >> b;
        cout << mp[a][b] << "\n";
        cout.flush();
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    intt t = 1;
    // cin >> t;
    while(t--){
        // cout << endl;
        _();
    }
}
// ⠀⠀⠀⠀⠀⠀⠀⢀⣤⣦⣶⣤⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⣤⢀⣀⡀⣠⣄⣠⣶⣿⣿⣿⣿⣿⣿⣿⣷⣾⡦⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠻⡳⢛⠛⠒⠚⢛⣿⣿⠟⠋⠉⠛⠛⢿⣿⣿⣿⠇⠀⠀⠀⠀⠀⠀⠀⠀
// ⢛⡛⢿⣿⠟⠻⠛⣿⣇⣶⣖⣤⣀⣄⡰⣹⣿⡟⠁⠀⠀⠀⠀⠀⠀⠀⠀
// ⢿⠿⠿⠿⠿⠿⠿⢭⣐⠠⢼⣬⠽⢈⢁⡿⠛⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⣛⣱⣤⣤⣤⣀⣄⣄⣗⢌⠋⠉⢙⣴⣧⢤⣤⣤⣤⣦⡀⠀⠀⠀⠀⢺⡿
// ⣿⣿⣿⠟⠛⠋⠀⡬⠼⢠⠍⠂⠀⠨⡇⠀⡏⠉⠛⢿⣧⠀⠀⠀⠀⢸⣀
// ⣟⠄⠀⠀⠀⠀⠀⢡⠀⠀⠀⠀⠀⡠⠁⢀⠁⠀⠀⠀⠘⣗⢀⠄⢶⣼⣾
// ⠀⠀⠀⢠⣦⠇⠀⠀⠁⠒⠒⠒⠈⠀⠀⠀⣞⢶⡀⠀⠀⠹⣧⣠⡞⣸⣏
// ⠀⠀⢀⡞⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⣿⣦⡀⠀⠈⠫⣕⣻⡇
// ⠀⠀⣾⣧⠈⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⣿⣿⣿⣷⣦⡠⡤⠀⣿⡇
// ⠠⢿⣿⣿⠂⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⠀⠴⣿⣿⣿⣿⠟⠋⢀⣤⣿⣷
// ⣀⣀⣀⣙⣃⣠⣤⣔⣤⣢⣵⣒⣒⣢⣄⣤⣄⣛⣋⣉⣀⣀⣤⣿⣿⣿⣿
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...