Submission #156122

#TimeUsernameProblemLanguageResultExecution timeMemory
156122NnandiRegions (IOI09_regions)C++14
30 / 100
1511 ms32888 KiB
#include <bits/stdc++.h> #define ll long long #define ft(n,i) for (ll i=0;i<n;i++) #define tft(n,l,i) for (ll i=l;i<n;i++) #define vi vector<ll> using namespace std; vi h,s; vector<vi > graph; ll to[510][510], most[510]; void bej(ll x) { most[h[x]]++; ft (510,i) to[i][h[x]]+=most[i]; for (ll f: graph[x]) { bej(f); } most[h[x]]--; } int main() { ios::sync_with_stdio(0); ll n,r,q; cin>>n>>r>>q; h.assign(n+1,0); s.assign(n+1,0); graph.assign(n+1,vi()); cin>>h[1]; tft(n+1,2,i) { cin>>s[i]>>h[i]; graph[s[i]].push_back(i); } bej(1); ft (q,i) { ll a,b; cin>>a>>b; cout<<to[a][b]<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...