Submission #1126287

#TimeUsernameProblemLanguageResultExecution timeMemory
1126287alecurseRegions (IOI09_regions)C++20
0 / 100
2 ms508 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); // 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)

regions.cpp: In function 'int main()':
regions.cpp:46:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     freopen("input.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
regions.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     freopen("output.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...