# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1126288 | alecurse | Regions (IOI09_regions) | C++20 | 2 ms | 508 KiB |
#include <iostream>
#include <vector>
#include <unordered_map>
#define ll long long int
using namespace std;
ll N, R, Q;
vector<ll> regions;
vector<vector<ll> > adj;
vector<ll> ans;
vector<unordered_map<ll,ll> > sets;
vector<unordered_map<ll,ll> > res;
vector<unordered_map<ll,vector<ll> > > regionsqueries;
void dfs(ll x) {
for(auto b : adj[x]) {
dfs(b);
if(sets[b].size()>sets[x].size()) {
swap(sets[b],sets[x]);
}
for(auto el : sets[b]) {
sets[x][el.first]+=el.second;
}
}
// if(sets[x].size()<regionsqueries[regions[x]].size()) {
for(auto el : sets[x]) {
// if(regionsqueries[regions[x]].count(el.first)) {
// for(auto index : regionsqueries[regions[x]][el.first]) {
// ans[index]+=el.second;
// }
// }
res[regions[x]][el.first]+=el.second;
}
// } else {
// for(auto el : regionsqueries[regions[x]]) {
// if(sets[x].count(el.first)) {
// for(auto index : el.second) {
// ans[index]+=sets[x][el.first];
// }
// }
// }
// }
sets[x][regions[x]]++;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
cin>>N>>R>>Q;
regions.resize(N);
adj.resize(N);
sets.resize(N);
cin>>regions[0];
regions[0]--;
for(ll i=1;i<N;i++) {
ll p;
cin>>p;
p--;
adj[p].push_back(i);
cin>>regions[i];
regions[i]--;
}
ans.resize(Q);
regions.resize(R);
res.resize(R);
// regionsqueries.resize(R);
// for(ll i=0;i<Q;i++) {
// ll r1, r2;
// cin>>r1>>r2;
// r1--;
// r2--;
// regionsqueries[r1][r2].push_back(i);
// }
dfs(0);
for(ll i=0;i<Q;i++) {
ll r1, r2;
cin>>r1>>r2;
r1--;
r2--;
// regionsqueries[r1][r2].push_back(i);
cout<<42<<"\n";
}
for(ll i=0;i<Q;i++) {
cout<<ans[i]<<"\n";
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |