Submission #527924

#TimeUsernameProblemLanguageResultExecution timeMemory
527924MohamedAliSaidaneRegions (IOI09_regions)C++14
0 / 100
421 ms131076 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<ld,ld> pld; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pii> vpi; typedef vector<pll> vpl; typedef vector<pld> vpd; #define pb push_back #define pf push_front #define popb pop_back #define popf pop_front #define all(v) (v).begin(),(v).end() #define ff first #define ss second const ll MOD = 1e9 + 7; const ll INF = 1e18; int nx[4] = {1,-1,0,0}, ny[4] = {0,0,1,-1}; ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} ll lcm(ll a, ll b){return (a / gcd(a, b)) * b;} const int MAX_R = 504; const int MAX_N =2e5 + 4; ll sup[MAX_N][MAX_R]; int reg[MAX_N]; vi adj[MAX_N]; int n, r, q; int p[MAX_N]; void dfs(int x) { for(auto e: adj[x]) { dfs(e); for(int h = 1; h <= r;h ++) { sup[x][h] += sup[e][h] + (reg[e] == h); } } return; } void solve() { cin >> n >> r >> q; cin >> reg[1]; map<int,vi> m; m[reg[1]].pb(1); for(int i = 2; i <= n; i ++) { cin >> p[i] >> reg[i]; adj[p[i]].pb(i); m[reg[i]].pb(i); } dfs(1); while(q--) { int u, v; cin >> u >> v; ll tot = 0ll; for(auto e: m[u]) tot += sup[e][v]; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tt = 1; while(tt--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...