제출 #526464

#제출 시각아이디문제언어결과실행 시간메모리
526464PiejanVDCRegions (IOI09_regions)C++17
19 / 100
8055 ms131076 KiB
#include <bits/stdc++.h>
using namespace std;

vector<int>top;
vector<int>adj[(int)2e5+5];
vector<int>region;

map<pair<int,int>,int>mp;

void dfs(int u, int e = -1) {
    for(auto z : top) {
        mp[{region[u],region[z]}]++;
    }
    top.push_back(u);
    for(auto z : adj[u]) if(z != e) {
        dfs(z,u);
    }
    top.pop_back();
}

signed main() {
    int n,r,q; cin>>n>>r>>q;
    region.resize(n);
    int h; cin>>h; region[0] = h;
    for(int i = 1 ; i < n ; i++) {
        int s,h; cin>>s>>h;
        s--;
        adj[s].push_back(i);
        region[i] = h;
    }
    dfs(0);
    while(q--) {
        int a,b; cin>>a>>b;
        cout << flush << mp[{b,a}] << "\n";
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...