Submission #321326

#TimeUsernameProblemLanguageResultExecution timeMemory
321326ronnithRegions (IOI09_regions)C++14
30 / 100
1612 ms131076 KiB
#include <bits/stdc++.h> #define FOR(i,a,b) for(int i = a;i < b;i ++) #define trav(e,x) for(auto e:x) #define maxn 200000 #define maxr 5000 using ll = long long; using namespace std; ll N, R, Q, region[maxn], ans[maxr][maxr]; vector<ll> adj[maxn]; void dfs(ll x,ll pr,ll crr,ll val) { if(region[x] == crr)val ++; ans[crr][region[x]] += val; trav(e,adj[x]) { if(e != pr) { dfs(e,x,crr,val); } } } void preProccess() { FOR(i,0,R) { dfs(0,-1,i,0); } } int main() { scanf("%lld%lld%lld",&N,&R,&Q); ll x,y; scanf("%lld",&x); region[0] = x - 1; FOR(i,0,N - 1) { scanf("%lld%lld",&x,&y); x --;y --; adj[i + 1].push_back(x); adj[x].push_back(i + 1); region[i + 1] = y; } FOR(i,0,R) { fill(ans[i],ans[i] + R,0); } preProccess(); FOR(i,0,Q) { scanf("%lld%lld",&x,&y); x --;y --; printf("%lld\n", ans[x][y]); fflush(stdout); } return 0; }

Compilation message (stderr)

regions.cpp: In function 'int main()':
regions.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |  scanf("%lld%lld%lld",&N,&R,&Q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
regions.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   41 |  scanf("%lld",&x);
      |  ~~~~~^~~~~~~~~~~
regions.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |   scanf("%lld%lld",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
regions.cpp:60:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   60 |   scanf("%lld%lld",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...