# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
627300 |
2022-08-12T12:20:33 Z |
clams |
Regions (IOI09_regions) |
C++17 |
|
846 ms |
45468 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int R = 25e3 + 5;
const int Q = 2e5 + 5;
int n, r, q;
int home[N], par[N];
vector<int> adj[N];
const int R1 = 505;
map<int, int> mp[N];
int pre[R1][R1];
void dfs(int u, int p) {
for (int v : adj[u]) {
if (v == p) continue;
dfs(v, u);
if (mp[u].size() < mp[v].size()) swap(mp[u], mp[v]);
for (auto i : mp[v]) mp[u][i.first] += i.second;
}
for (auto i : mp[u]) {
pre[home[u]][i.first] += i.second;
}
mp[u][home[u]]++;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> r >> q;
cin >> home[1];
for (int i = 2; i <= n; i++) {
cin >> par[i] >> home[i];
adj[par[i]].push_back(i);
adj[i].push_back(par[i]);
}
if (r < R1) {
dfs(1, 0);
while (q--) {
int r1, r2;
cin >> r1 >> r2;
cout << pre[r1][r2] << endl;
}
} else {
assert(false);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14416 KB |
Output is correct |
2 |
Correct |
8 ms |
14364 KB |
Output is correct |
3 |
Correct |
9 ms |
14520 KB |
Output is correct |
4 |
Correct |
11 ms |
14416 KB |
Output is correct |
5 |
Correct |
17 ms |
14544 KB |
Output is correct |
6 |
Correct |
29 ms |
14968 KB |
Output is correct |
7 |
Correct |
18 ms |
14848 KB |
Output is correct |
8 |
Correct |
37 ms |
14928 KB |
Output is correct |
9 |
Correct |
52 ms |
15848 KB |
Output is correct |
10 |
Correct |
84 ms |
16500 KB |
Output is correct |
11 |
Correct |
65 ms |
16480 KB |
Output is correct |
12 |
Correct |
145 ms |
17020 KB |
Output is correct |
13 |
Correct |
125 ms |
18704 KB |
Output is correct |
14 |
Correct |
156 ms |
18376 KB |
Output is correct |
15 |
Correct |
281 ms |
21460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
677 ms |
21060 KB |
Output is correct |
2 |
Correct |
697 ms |
24008 KB |
Output is correct |
3 |
Correct |
846 ms |
23432 KB |
Output is correct |
4 |
Runtime error |
26 ms |
31464 KB |
Execution killed with signal 6 |
5 |
Runtime error |
31 ms |
31960 KB |
Execution killed with signal 6 |
6 |
Runtime error |
34 ms |
33232 KB |
Execution killed with signal 6 |
7 |
Runtime error |
43 ms |
34624 KB |
Execution killed with signal 6 |
8 |
Runtime error |
60 ms |
36956 KB |
Execution killed with signal 6 |
9 |
Runtime error |
61 ms |
41032 KB |
Execution killed with signal 6 |
10 |
Runtime error |
70 ms |
42560 KB |
Execution killed with signal 6 |
11 |
Runtime error |
71 ms |
45468 KB |
Execution killed with signal 6 |
12 |
Runtime error |
76 ms |
44132 KB |
Execution killed with signal 6 |
13 |
Runtime error |
68 ms |
44244 KB |
Execution killed with signal 6 |
14 |
Runtime error |
104 ms |
44916 KB |
Execution killed with signal 6 |
15 |
Runtime error |
90 ms |
45008 KB |
Execution killed with signal 6 |
16 |
Runtime error |
72 ms |
44924 KB |
Execution killed with signal 6 |
17 |
Runtime error |
72 ms |
44912 KB |
Execution killed with signal 6 |