#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3e3 + 10;
int n, m, q;
vector<int> g[N];
int sm[N];
void calc(int s, int p) {
for(int to : g[s]) {
if(to == p) continue;
calc(to, s);
sm[s] += sm[to];
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n >> m >> q;
for(int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
vector<int> ver(m + 1);
for(int i = 1; i <= m; i++)
cin >> ver[i];
while(q --> 0) {
int l, r;
cin >> l >> r;
for(int i = l; i <= r; i++)
sm[ver[i]]++;
calc(1, 1);
int res = 1;
for(int i = 1; i <= n; i++) {
res += (sm[i] && sm[i] < r - l + 1);
sm[i] = 0;
}
cout << res << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
21 ms |
340 KB |
Output is correct |
31 |
Correct |
25 ms |
456 KB |
Output is correct |
32 |
Correct |
41 ms |
472 KB |
Output is correct |
33 |
Correct |
40 ms |
472 KB |
Output is correct |
34 |
Correct |
40 ms |
468 KB |
Output is correct |
35 |
Correct |
37 ms |
484 KB |
Output is correct |
36 |
Correct |
31 ms |
472 KB |
Output is correct |
37 |
Correct |
31 ms |
480 KB |
Output is correct |
38 |
Correct |
42 ms |
588 KB |
Output is correct |
39 |
Correct |
47 ms |
468 KB |
Output is correct |
40 |
Correct |
45 ms |
588 KB |
Output is correct |
41 |
Correct |
43 ms |
596 KB |
Output is correct |
42 |
Correct |
43 ms |
616 KB |
Output is correct |
43 |
Correct |
42 ms |
568 KB |
Output is correct |
44 |
Correct |
45 ms |
532 KB |
Output is correct |
45 |
Correct |
44 ms |
512 KB |
Output is correct |
46 |
Correct |
44 ms |
468 KB |
Output is correct |
47 |
Correct |
46 ms |
520 KB |
Output is correct |
48 |
Correct |
49 ms |
496 KB |
Output is correct |
49 |
Correct |
48 ms |
524 KB |
Output is correct |
50 |
Correct |
28 ms |
476 KB |
Output is correct |
51 |
Correct |
32 ms |
504 KB |
Output is correct |
52 |
Correct |
28 ms |
468 KB |
Output is correct |
53 |
Correct |
29 ms |
488 KB |
Output is correct |
54 |
Correct |
30 ms |
484 KB |
Output is correct |
55 |
Correct |
29 ms |
484 KB |
Output is correct |
56 |
Correct |
4 ms |
340 KB |
Output is correct |
57 |
Correct |
27 ms |
468 KB |
Output is correct |
58 |
Correct |
28 ms |
476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
340 KB |
Output is correct |
4 |
Runtime error |
1 ms |
724 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Runtime error |
1 ms |
724 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
21 ms |
340 KB |
Output is correct |
31 |
Correct |
25 ms |
456 KB |
Output is correct |
32 |
Correct |
41 ms |
472 KB |
Output is correct |
33 |
Correct |
40 ms |
472 KB |
Output is correct |
34 |
Correct |
40 ms |
468 KB |
Output is correct |
35 |
Correct |
37 ms |
484 KB |
Output is correct |
36 |
Correct |
31 ms |
472 KB |
Output is correct |
37 |
Correct |
31 ms |
480 KB |
Output is correct |
38 |
Correct |
42 ms |
588 KB |
Output is correct |
39 |
Correct |
47 ms |
468 KB |
Output is correct |
40 |
Correct |
45 ms |
588 KB |
Output is correct |
41 |
Correct |
43 ms |
596 KB |
Output is correct |
42 |
Correct |
43 ms |
616 KB |
Output is correct |
43 |
Correct |
42 ms |
568 KB |
Output is correct |
44 |
Correct |
45 ms |
532 KB |
Output is correct |
45 |
Correct |
44 ms |
512 KB |
Output is correct |
46 |
Correct |
44 ms |
468 KB |
Output is correct |
47 |
Correct |
46 ms |
520 KB |
Output is correct |
48 |
Correct |
49 ms |
496 KB |
Output is correct |
49 |
Correct |
48 ms |
524 KB |
Output is correct |
50 |
Correct |
28 ms |
476 KB |
Output is correct |
51 |
Correct |
32 ms |
504 KB |
Output is correct |
52 |
Correct |
28 ms |
468 KB |
Output is correct |
53 |
Correct |
29 ms |
488 KB |
Output is correct |
54 |
Correct |
30 ms |
484 KB |
Output is correct |
55 |
Correct |
29 ms |
484 KB |
Output is correct |
56 |
Correct |
4 ms |
340 KB |
Output is correct |
57 |
Correct |
27 ms |
468 KB |
Output is correct |
58 |
Correct |
28 ms |
476 KB |
Output is correct |
59 |
Correct |
0 ms |
340 KB |
Output is correct |
60 |
Correct |
0 ms |
340 KB |
Output is correct |
61 |
Correct |
4 ms |
340 KB |
Output is correct |
62 |
Runtime error |
1 ms |
724 KB |
Execution killed with signal 11 |
63 |
Halted |
0 ms |
0 KB |
- |