#include <iostream>
#include <fstream>
#include <cfloat>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstring>
#include <cmath>
#include <climits>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<string> vs;
#define fir first
#define sec second
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
vi country;
vvi G;
int N, R;
vector<map<int, int>> below;
vvi countryCit;
void dfs(int S) {
for (auto v: G[S]) {
dfs(v);
for (auto const &a: below[v]) {
below[S][a.first] += below[v][a.first];
}
below[S][country[v]-1]++;
}
}
int main() {
//ios::sync_with_stdio(false);
//cin.tie(NULL);
int Q, cn, sup, e1, e2, ans;
cin >> N >> R >> Q;
G.assign(N, vi());
countryCit.assign(N, vi());
country = vi(N);
below.assign(N, map<int, int>());
cin >> cn;
country[0] = cn;
countryCit[cn-1].pb(0);
for (int i = 1; i < N; i++) {
cin >> sup >> cn;
G[sup-1].push_back(i);
country[i] = cn;
countryCit[cn-1].pb(i);
}
dfs(0);
while(Q--) {
cin >> e1 >> e2;
ans = 0;
for (auto cit: countryCit[e1-1]) {
ans += below[cit][e2-1];
}
cout << ans << "\n";
cout.flush();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
548 KB |
Output is correct |
5 |
Correct |
11 ms |
1024 KB |
Output is correct |
6 |
Correct |
52 ms |
7160 KB |
Output is correct |
7 |
Correct |
45 ms |
2936 KB |
Output is correct |
8 |
Correct |
61 ms |
5240 KB |
Output is correct |
9 |
Correct |
336 ms |
68284 KB |
Output is correct |
10 |
Correct |
209 ms |
20088 KB |
Output is correct |
11 |
Correct |
477 ms |
54132 KB |
Output is correct |
12 |
Runtime error |
447 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
13 |
Correct |
607 ms |
52080 KB |
Output is correct |
14 |
Correct |
1364 ms |
108140 KB |
Output is correct |
15 |
Runtime error |
424 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
455 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Runtime error |
591 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Runtime error |
481 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
4 |
Runtime error |
507 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
5 |
Runtime error |
473 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
6 |
Runtime error |
498 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
7 |
Runtime error |
514 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
8 |
Runtime error |
530 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
9 |
Runtime error |
576 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
10 |
Runtime error |
579 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
11 |
Runtime error |
664 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
12 |
Runtime error |
604 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
13 |
Runtime error |
614 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
14 |
Runtime error |
644 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
15 |
Runtime error |
602 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
16 |
Runtime error |
556 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
17 |
Runtime error |
609 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |