#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
using namespace std;
const ll maxn=100005;
vector <ll> A[maxn];
vector <pll> L[maxn];
ll n, m, q, c[maxn], a[maxn], ans[maxn], pa[maxn], dep[maxn];
void dfs(ll u)
{
for (ll v:A[u])
if (v!=pa[u])
{
dep[v]=dep[u]+1;
pa[v]=u, dfs(v);
}
}
void update(ll u, ll v, ll val)
{
for (; u!=v; u=pa[u])
{
if (dep[u]<dep[v]) swap(u, v);
a[u]=val;
}
a[u]=val;
}
ll query(ll l, ll r)
{
ll ans=0;
for (ll i=1; i<=n; i++)
if (l<=a[i] && a[i]<=r)
ans++;
return ans;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m >> q;
for (ll i=1; i<n; i++)
{
ll u, v; cin >> u >> v;
A[u].pb(v); A[v].pb(u);
}
dfs(1);
for (ll i=1; i<=m; i++)
cin >> c[i];
for (ll i=1; i<=q; i++)
{
ll l, r; cin >> l >> r;
L[r].pb({l, i});
}
for (ll i=1; i<=m; i++)
{
if (i>1) update(c[i-1], c[i], i-1);
update(c[i], c[i], i);
for (auto &[l, idx]:L[i])
ans[idx]=query(l, i);
}
for (ll i=1; i<=q; i++)
cout << ans[i] << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6848 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6848 KB |
Output is correct |
6 |
Correct |
2 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6744 KB |
Output is correct |
8 |
Correct |
2 ms |
7204 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
1 ms |
6748 KB |
Output is correct |
11 |
Correct |
2 ms |
6748 KB |
Output is correct |
12 |
Correct |
2 ms |
6748 KB |
Output is correct |
13 |
Correct |
2 ms |
6748 KB |
Output is correct |
14 |
Correct |
2 ms |
6748 KB |
Output is correct |
15 |
Correct |
2 ms |
6748 KB |
Output is correct |
16 |
Correct |
2 ms |
6748 KB |
Output is correct |
17 |
Correct |
2 ms |
6748 KB |
Output is correct |
18 |
Correct |
2 ms |
6748 KB |
Output is correct |
19 |
Correct |
2 ms |
6748 KB |
Output is correct |
20 |
Correct |
2 ms |
6748 KB |
Output is correct |
21 |
Correct |
2 ms |
6844 KB |
Output is correct |
22 |
Correct |
1 ms |
6748 KB |
Output is correct |
23 |
Correct |
2 ms |
6748 KB |
Output is correct |
24 |
Correct |
2 ms |
6748 KB |
Output is correct |
25 |
Correct |
2 ms |
7256 KB |
Output is correct |
26 |
Correct |
1 ms |
6748 KB |
Output is correct |
27 |
Correct |
1 ms |
8796 KB |
Output is correct |
28 |
Correct |
1 ms |
7000 KB |
Output is correct |
29 |
Correct |
2 ms |
6744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6848 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6848 KB |
Output is correct |
6 |
Correct |
2 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6744 KB |
Output is correct |
8 |
Correct |
2 ms |
7204 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
1 ms |
6748 KB |
Output is correct |
11 |
Correct |
2 ms |
6748 KB |
Output is correct |
12 |
Correct |
2 ms |
6748 KB |
Output is correct |
13 |
Correct |
2 ms |
6748 KB |
Output is correct |
14 |
Correct |
2 ms |
6748 KB |
Output is correct |
15 |
Correct |
2 ms |
6748 KB |
Output is correct |
16 |
Correct |
2 ms |
6748 KB |
Output is correct |
17 |
Correct |
2 ms |
6748 KB |
Output is correct |
18 |
Correct |
2 ms |
6748 KB |
Output is correct |
19 |
Correct |
2 ms |
6748 KB |
Output is correct |
20 |
Correct |
2 ms |
6748 KB |
Output is correct |
21 |
Correct |
2 ms |
6844 KB |
Output is correct |
22 |
Correct |
1 ms |
6748 KB |
Output is correct |
23 |
Correct |
2 ms |
6748 KB |
Output is correct |
24 |
Correct |
2 ms |
6748 KB |
Output is correct |
25 |
Correct |
2 ms |
7256 KB |
Output is correct |
26 |
Correct |
1 ms |
6748 KB |
Output is correct |
27 |
Correct |
1 ms |
8796 KB |
Output is correct |
28 |
Correct |
1 ms |
7000 KB |
Output is correct |
29 |
Correct |
2 ms |
6744 KB |
Output is correct |
30 |
Correct |
4 ms |
7004 KB |
Output is correct |
31 |
Correct |
4 ms |
7004 KB |
Output is correct |
32 |
Correct |
5 ms |
7004 KB |
Output is correct |
33 |
Correct |
5 ms |
6952 KB |
Output is correct |
34 |
Correct |
5 ms |
7004 KB |
Output is correct |
35 |
Correct |
5 ms |
7000 KB |
Output is correct |
36 |
Correct |
5 ms |
7004 KB |
Output is correct |
37 |
Correct |
5 ms |
7072 KB |
Output is correct |
38 |
Correct |
9 ms |
7256 KB |
Output is correct |
39 |
Correct |
10 ms |
7004 KB |
Output is correct |
40 |
Correct |
9 ms |
7004 KB |
Output is correct |
41 |
Correct |
9 ms |
7004 KB |
Output is correct |
42 |
Correct |
9 ms |
7116 KB |
Output is correct |
43 |
Correct |
8 ms |
7004 KB |
Output is correct |
44 |
Correct |
7 ms |
7004 KB |
Output is correct |
45 |
Correct |
6 ms |
6856 KB |
Output is correct |
46 |
Correct |
7 ms |
7004 KB |
Output is correct |
47 |
Correct |
6 ms |
7004 KB |
Output is correct |
48 |
Correct |
6 ms |
7000 KB |
Output is correct |
49 |
Correct |
7 ms |
7000 KB |
Output is correct |
50 |
Correct |
5 ms |
7004 KB |
Output is correct |
51 |
Correct |
6 ms |
7004 KB |
Output is correct |
52 |
Correct |
5 ms |
7004 KB |
Output is correct |
53 |
Correct |
8 ms |
7004 KB |
Output is correct |
54 |
Correct |
7 ms |
7004 KB |
Output is correct |
55 |
Correct |
6 ms |
6844 KB |
Output is correct |
56 |
Correct |
3 ms |
8796 KB |
Output is correct |
57 |
Correct |
5 ms |
7000 KB |
Output is correct |
58 |
Correct |
6 ms |
7004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6748 KB |
Output is correct |
2 |
Correct |
2 ms |
8892 KB |
Output is correct |
3 |
Correct |
3 ms |
8792 KB |
Output is correct |
4 |
Execution timed out |
5090 ms |
16800 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6748 KB |
Output is correct |
2 |
Correct |
108 ms |
10516 KB |
Output is correct |
3 |
Correct |
114 ms |
10824 KB |
Output is correct |
4 |
Correct |
123 ms |
11600 KB |
Output is correct |
5 |
Correct |
49 ms |
13612 KB |
Output is correct |
6 |
Correct |
56 ms |
13652 KB |
Output is correct |
7 |
Correct |
47 ms |
13820 KB |
Output is correct |
8 |
Correct |
47 ms |
13648 KB |
Output is correct |
9 |
Correct |
67 ms |
13760 KB |
Output is correct |
10 |
Correct |
72 ms |
13748 KB |
Output is correct |
11 |
Correct |
119 ms |
13916 KB |
Output is correct |
12 |
Correct |
264 ms |
14000 KB |
Output is correct |
13 |
Correct |
794 ms |
14352 KB |
Output is correct |
14 |
Correct |
2279 ms |
15452 KB |
Output is correct |
15 |
Execution timed out |
5058 ms |
18748 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6748 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
3981 ms |
15792 KB |
Output is correct |
5 |
Correct |
3837 ms |
15740 KB |
Output is correct |
6 |
Execution timed out |
5033 ms |
17208 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6848 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6848 KB |
Output is correct |
6 |
Correct |
2 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6744 KB |
Output is correct |
8 |
Correct |
2 ms |
7204 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
1 ms |
6748 KB |
Output is correct |
11 |
Correct |
2 ms |
6748 KB |
Output is correct |
12 |
Correct |
2 ms |
6748 KB |
Output is correct |
13 |
Correct |
2 ms |
6748 KB |
Output is correct |
14 |
Correct |
2 ms |
6748 KB |
Output is correct |
15 |
Correct |
2 ms |
6748 KB |
Output is correct |
16 |
Correct |
2 ms |
6748 KB |
Output is correct |
17 |
Correct |
2 ms |
6748 KB |
Output is correct |
18 |
Correct |
2 ms |
6748 KB |
Output is correct |
19 |
Correct |
2 ms |
6748 KB |
Output is correct |
20 |
Correct |
2 ms |
6748 KB |
Output is correct |
21 |
Correct |
2 ms |
6844 KB |
Output is correct |
22 |
Correct |
1 ms |
6748 KB |
Output is correct |
23 |
Correct |
2 ms |
6748 KB |
Output is correct |
24 |
Correct |
2 ms |
6748 KB |
Output is correct |
25 |
Correct |
2 ms |
7256 KB |
Output is correct |
26 |
Correct |
1 ms |
6748 KB |
Output is correct |
27 |
Correct |
1 ms |
8796 KB |
Output is correct |
28 |
Correct |
1 ms |
7000 KB |
Output is correct |
29 |
Correct |
2 ms |
6744 KB |
Output is correct |
30 |
Correct |
4 ms |
7004 KB |
Output is correct |
31 |
Correct |
4 ms |
7004 KB |
Output is correct |
32 |
Correct |
5 ms |
7004 KB |
Output is correct |
33 |
Correct |
5 ms |
6952 KB |
Output is correct |
34 |
Correct |
5 ms |
7004 KB |
Output is correct |
35 |
Correct |
5 ms |
7000 KB |
Output is correct |
36 |
Correct |
5 ms |
7004 KB |
Output is correct |
37 |
Correct |
5 ms |
7072 KB |
Output is correct |
38 |
Correct |
9 ms |
7256 KB |
Output is correct |
39 |
Correct |
10 ms |
7004 KB |
Output is correct |
40 |
Correct |
9 ms |
7004 KB |
Output is correct |
41 |
Correct |
9 ms |
7004 KB |
Output is correct |
42 |
Correct |
9 ms |
7116 KB |
Output is correct |
43 |
Correct |
8 ms |
7004 KB |
Output is correct |
44 |
Correct |
7 ms |
7004 KB |
Output is correct |
45 |
Correct |
6 ms |
6856 KB |
Output is correct |
46 |
Correct |
7 ms |
7004 KB |
Output is correct |
47 |
Correct |
6 ms |
7004 KB |
Output is correct |
48 |
Correct |
6 ms |
7000 KB |
Output is correct |
49 |
Correct |
7 ms |
7000 KB |
Output is correct |
50 |
Correct |
5 ms |
7004 KB |
Output is correct |
51 |
Correct |
6 ms |
7004 KB |
Output is correct |
52 |
Correct |
5 ms |
7004 KB |
Output is correct |
53 |
Correct |
8 ms |
7004 KB |
Output is correct |
54 |
Correct |
7 ms |
7004 KB |
Output is correct |
55 |
Correct |
6 ms |
6844 KB |
Output is correct |
56 |
Correct |
3 ms |
8796 KB |
Output is correct |
57 |
Correct |
5 ms |
7000 KB |
Output is correct |
58 |
Correct |
6 ms |
7004 KB |
Output is correct |
59 |
Correct |
2 ms |
6748 KB |
Output is correct |
60 |
Correct |
2 ms |
8892 KB |
Output is correct |
61 |
Correct |
3 ms |
8792 KB |
Output is correct |
62 |
Execution timed out |
5090 ms |
16800 KB |
Time limit exceeded |
63 |
Halted |
0 ms |
0 KB |
- |