Submission #1013399

#TimeUsernameProblemLanguageResultExecution timeMemory
1013399vjudge1Regions (IOI09_regions)C++17
30 / 100
5578 ms131076 KiB
#include<bits/stdc++.h> using namespace std; #ifdef ONPC #include"debug.h" #else #define debug(...) 42 #endif #define endl '\n' #define ll long long #define pii pair<int,int> #define F first #define S second #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } const int mod = 1e9 + 7; const int MAXN = 1e6 + 15; const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; const int C = 500; int frq[MAXN], col[MAXN]; int n, r, q; vector<int> deco; int ans[503][25001]; pii upper; vector<int> adj[MAXN]; void dfs(int node, int cnt){ ans[upper.S][col[node]] += cnt; if (col[node] == upper.F) cnt++; for (auto to : adj[node]){ dfs(to, cnt); } } int main(){ //ios_base::sync_with_stdio(0); //cin.tie(0); cin >> n >> r >> q >> col[1]; for (int i = 2; i <= n; i++){ int p, c; cin >> p >> c; adj[p].pb(i); col[i] = c; frq[c]++; } for (int i = 0; i <= 25000; i++){ if (frq[i] >= C){ deco.pb(i); } } for (int i = 1; i <= r; i++){ upper = {i, i}; dfs(1, 0); } //for (int i = 0; i < sz(deco); i++){ //upper = {deco[i], i}; //dfs(1, 0); //} while (q--){ int e1, e2; cin >> e1 >> e2; cout << ans[e1][e2] << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...