제출 #825391

#제출 시각아이디문제언어결과실행 시간메모리
825391serifefedartarRegions (IOI09_regions)C++17
5 / 100
67 ms15228 KiB
#include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0);cin.tie(0); typedef long long ll; #define f first #define s second #define MOD 1000000007 #define LOGN 20 #define MAXN 200005 #define pb push_back vector<vector<int>> graph; int ans[505][505], cnt[505][505]; int region[MAXN]; void dfs(int node, int parent) { for (int i = 0; i <= 500; i++) { cnt[node][i] = cnt[parent][i]; ans[i][region[node]] += cnt[node][i]; } cnt[node][region[node]]++; for (auto u : graph[node]) { dfs(u, node); } } int main() { fast memset(ans, 0, sizeof(ans)); memset(cnt, 0, sizeof(cnt)); int N, R, Q, S, r1, r2; cin >> N >> R >> Q >> region[1]; graph = vector<vector<int>>(N+1, vector<int>()); for (int i = 2; i <= N; i++) { cin >> S >> region[i]; graph[S].pb(i); } if (R <= 500) { dfs(1, 1); while (Q--) { cin >> r1 >> r2; cout << ans[r1][r2] << endl; } } else { while (Q--) { int x, y; cin >> x >> y; cout << x << " " << y << endl; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...