Submission #1083271

#TimeUsernameProblemLanguageResultExecution timeMemory
1083271rayan_bdRegions (IOI09_regions)C++17
0 / 100
246 ms131072 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define ll long long const int mxN = 2e5 + 5000; ll color[mxN][505]; vector<ll> adj[mxN]; ll hd[mxN],out[mxN]; unordered_map<ll,vector<ll>> mp; void solve(ll tc) { ll n,r,q,r1,r2,super;cin>>n>>r>>q; cin>>hd[1]; mp[hd[1]].pb(1); color[1][hd[1]]=1; for(ll i=2;i<=n;++i){ cin>>super>>hd[i]; adj[i].pb(super); mp[hd[i]].pb(i); color[i][hd[i]]=1; ++out[super]; } set<ll> st; for(ll i=1;i<=n;++i){ if(out[i]==0){ st.insert(i); } } while(st.size()){ ll u=*st.begin(); st.erase(u); for(auto it:adj[u]){ for(ll i=1;i<505;++i){ color[it][i]+=color[u][i]; } if(--out[it]==0) st.insert(it); } } while(q--){ cin>>r1>>r2; ll ans=0; for(auto it:mp[hd[r1]]){ ans+=color[it][r2]; } cout.flush()<<ans<<'\n'; cout.flush(); } } void testing(){ #ifndef ONLINE_JUDGE freopen("input.in","r",stdin); freopen("output.out","w",stdout); #endif } int main() { //testing(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(0); return 0; }

Compilation message (stderr)

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