이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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
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 time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |