#include <bits/stdc++.h>
using namespace std;
const int nx=2e3+5, kx=11;
int n, m, q, u, v, lvl[nx], pa[nx][kx], t, l, r, vl, x;
vector<int> d[nx], a(nx);
void dfs(int u, int p)
{
lvl[u]=lvl[p]+1;
pa[u][0]=p;
for (int i=1; i<kx; i++) pa[u][i]=pa[pa[u][i-1]][i-1];
for (auto v:d[u]) if (v!=p) dfs(v, u);
}
int lca(int u, int v)
{
if (lvl[u]>lvl[v]) swap(u, v);
for (int i=kx-1; i>=0; i--) if (lvl[pa[v][i]]>=lvl[u]) v=pa[v][i];
if (u==v) return u;
for (int i=kx-1; i>=0; i--) if (pa[u][i]!=pa[v][i]) u=pa[u][i], v=pa[v][i];
return pa[u][0];
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m>>q;
for (int i=0; i<n-1; i++) cin>>u>>v, d[u].push_back(v), d[v].push_back(u);
dfs(1, 1);
for (int i=1; i<=m; i++) cin>>a[i];
while (q--)
{
cin>>t;
if (t==1) cin>>x>>vl, a[x]=vl;
else
{
cin>>l>>r>>vl;
int c=-1, idx=l;
for (int i=l; i<=r; i++)
{
if (c==-1) c=a[i];
else c=lca(c, a[i]);
if (c==vl)
{
cout<<idx<<' '<<i<<'\n';
break;
}
if (lca(c, vl)!=vl) c=-1, idx=i+1;
if (i==r) cout<<-1<<' '<<-1<<'\n';
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
n=5 |
2 |
Correct |
1 ms |
348 KB |
n=100 |
3 |
Correct |
1 ms |
348 KB |
n=100 |
4 |
Correct |
0 ms |
348 KB |
n=100 |
5 |
Correct |
0 ms |
348 KB |
n=100 |
6 |
Correct |
1 ms |
348 KB |
n=100 |
7 |
Correct |
1 ms |
516 KB |
n=100 |
8 |
Correct |
1 ms |
348 KB |
n=100 |
9 |
Correct |
1 ms |
348 KB |
n=100 |
10 |
Correct |
1 ms |
344 KB |
n=100 |
11 |
Correct |
1 ms |
344 KB |
n=100 |
12 |
Correct |
0 ms |
348 KB |
n=100 |
13 |
Correct |
1 ms |
348 KB |
n=100 |
14 |
Correct |
1 ms |
348 KB |
n=100 |
15 |
Correct |
0 ms |
348 KB |
n=100 |
16 |
Correct |
1 ms |
348 KB |
n=100 |
17 |
Correct |
0 ms |
348 KB |
n=100 |
18 |
Correct |
0 ms |
348 KB |
n=100 |
19 |
Correct |
0 ms |
348 KB |
n=100 |
20 |
Correct |
0 ms |
348 KB |
n=100 |
21 |
Correct |
1 ms |
348 KB |
n=100 |
22 |
Correct |
0 ms |
348 KB |
n=100 |
23 |
Correct |
1 ms |
344 KB |
n=100 |
24 |
Correct |
1 ms |
348 KB |
n=100 |
25 |
Correct |
1 ms |
348 KB |
n=100 |
26 |
Correct |
0 ms |
348 KB |
n=12 |
27 |
Correct |
1 ms |
348 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
n=5 |
2 |
Correct |
1 ms |
348 KB |
n=100 |
3 |
Correct |
1 ms |
348 KB |
n=100 |
4 |
Correct |
0 ms |
348 KB |
n=100 |
5 |
Correct |
0 ms |
348 KB |
n=100 |
6 |
Correct |
1 ms |
348 KB |
n=100 |
7 |
Correct |
1 ms |
516 KB |
n=100 |
8 |
Correct |
1 ms |
348 KB |
n=100 |
9 |
Correct |
1 ms |
348 KB |
n=100 |
10 |
Correct |
1 ms |
344 KB |
n=100 |
11 |
Correct |
1 ms |
344 KB |
n=100 |
12 |
Correct |
0 ms |
348 KB |
n=100 |
13 |
Correct |
1 ms |
348 KB |
n=100 |
14 |
Correct |
1 ms |
348 KB |
n=100 |
15 |
Correct |
0 ms |
348 KB |
n=100 |
16 |
Correct |
1 ms |
348 KB |
n=100 |
17 |
Correct |
0 ms |
348 KB |
n=100 |
18 |
Correct |
0 ms |
348 KB |
n=100 |
19 |
Correct |
0 ms |
348 KB |
n=100 |
20 |
Correct |
0 ms |
348 KB |
n=100 |
21 |
Correct |
1 ms |
348 KB |
n=100 |
22 |
Correct |
0 ms |
348 KB |
n=100 |
23 |
Correct |
1 ms |
344 KB |
n=100 |
24 |
Correct |
1 ms |
348 KB |
n=100 |
25 |
Correct |
1 ms |
348 KB |
n=100 |
26 |
Correct |
0 ms |
348 KB |
n=12 |
27 |
Correct |
1 ms |
348 KB |
n=100 |
28 |
Correct |
1 ms |
348 KB |
n=500 |
29 |
Correct |
2 ms |
348 KB |
n=500 |
30 |
Correct |
2 ms |
348 KB |
n=500 |
31 |
Correct |
2 ms |
348 KB |
n=500 |
32 |
Correct |
1 ms |
348 KB |
n=500 |
33 |
Correct |
2 ms |
348 KB |
n=500 |
34 |
Correct |
1 ms |
348 KB |
n=500 |
35 |
Correct |
2 ms |
528 KB |
n=500 |
36 |
Correct |
11 ms |
524 KB |
n=500 |
37 |
Correct |
11 ms |
348 KB |
n=500 |
38 |
Correct |
11 ms |
572 KB |
n=500 |
39 |
Correct |
6 ms |
348 KB |
n=500 |
40 |
Correct |
7 ms |
792 KB |
n=500 |
41 |
Correct |
6 ms |
344 KB |
n=500 |
42 |
Correct |
6 ms |
348 KB |
n=500 |
43 |
Correct |
6 ms |
348 KB |
n=500 |
44 |
Correct |
6 ms |
348 KB |
n=500 |
45 |
Correct |
1 ms |
348 KB |
n=500 |
46 |
Correct |
2 ms |
348 KB |
n=500 |
47 |
Correct |
2 ms |
348 KB |
n=500 |
48 |
Correct |
1 ms |
344 KB |
n=500 |
49 |
Correct |
2 ms |
344 KB |
n=500 |
50 |
Correct |
3 ms |
348 KB |
n=500 |
51 |
Correct |
3 ms |
348 KB |
n=500 |
52 |
Correct |
3 ms |
344 KB |
n=500 |
53 |
Correct |
3 ms |
348 KB |
n=500 |
54 |
Correct |
5 ms |
524 KB |
n=500 |
55 |
Correct |
1 ms |
348 KB |
n=278 |
56 |
Correct |
9 ms |
348 KB |
n=500 |
57 |
Correct |
9 ms |
600 KB |
n=500 |
58 |
Correct |
9 ms |
344 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
n=5 |
2 |
Correct |
1 ms |
348 KB |
n=100 |
3 |
Correct |
1 ms |
348 KB |
n=100 |
4 |
Correct |
0 ms |
348 KB |
n=100 |
5 |
Correct |
0 ms |
348 KB |
n=100 |
6 |
Correct |
1 ms |
348 KB |
n=100 |
7 |
Correct |
1 ms |
516 KB |
n=100 |
8 |
Correct |
1 ms |
348 KB |
n=100 |
9 |
Correct |
1 ms |
348 KB |
n=100 |
10 |
Correct |
1 ms |
344 KB |
n=100 |
11 |
Correct |
1 ms |
344 KB |
n=100 |
12 |
Correct |
0 ms |
348 KB |
n=100 |
13 |
Correct |
1 ms |
348 KB |
n=100 |
14 |
Correct |
1 ms |
348 KB |
n=100 |
15 |
Correct |
0 ms |
348 KB |
n=100 |
16 |
Correct |
1 ms |
348 KB |
n=100 |
17 |
Correct |
0 ms |
348 KB |
n=100 |
18 |
Correct |
0 ms |
348 KB |
n=100 |
19 |
Correct |
0 ms |
348 KB |
n=100 |
20 |
Correct |
0 ms |
348 KB |
n=100 |
21 |
Correct |
1 ms |
348 KB |
n=100 |
22 |
Correct |
0 ms |
348 KB |
n=100 |
23 |
Correct |
1 ms |
344 KB |
n=100 |
24 |
Correct |
1 ms |
348 KB |
n=100 |
25 |
Correct |
1 ms |
348 KB |
n=100 |
26 |
Correct |
0 ms |
348 KB |
n=12 |
27 |
Correct |
1 ms |
348 KB |
n=100 |
28 |
Correct |
1 ms |
348 KB |
n=500 |
29 |
Correct |
2 ms |
348 KB |
n=500 |
30 |
Correct |
2 ms |
348 KB |
n=500 |
31 |
Correct |
2 ms |
348 KB |
n=500 |
32 |
Correct |
1 ms |
348 KB |
n=500 |
33 |
Correct |
2 ms |
348 KB |
n=500 |
34 |
Correct |
1 ms |
348 KB |
n=500 |
35 |
Correct |
2 ms |
528 KB |
n=500 |
36 |
Correct |
11 ms |
524 KB |
n=500 |
37 |
Correct |
11 ms |
348 KB |
n=500 |
38 |
Correct |
11 ms |
572 KB |
n=500 |
39 |
Correct |
6 ms |
348 KB |
n=500 |
40 |
Correct |
7 ms |
792 KB |
n=500 |
41 |
Correct |
6 ms |
344 KB |
n=500 |
42 |
Correct |
6 ms |
348 KB |
n=500 |
43 |
Correct |
6 ms |
348 KB |
n=500 |
44 |
Correct |
6 ms |
348 KB |
n=500 |
45 |
Correct |
1 ms |
348 KB |
n=500 |
46 |
Correct |
2 ms |
348 KB |
n=500 |
47 |
Correct |
2 ms |
348 KB |
n=500 |
48 |
Correct |
1 ms |
344 KB |
n=500 |
49 |
Correct |
2 ms |
344 KB |
n=500 |
50 |
Correct |
3 ms |
348 KB |
n=500 |
51 |
Correct |
3 ms |
348 KB |
n=500 |
52 |
Correct |
3 ms |
344 KB |
n=500 |
53 |
Correct |
3 ms |
348 KB |
n=500 |
54 |
Correct |
5 ms |
524 KB |
n=500 |
55 |
Correct |
1 ms |
348 KB |
n=278 |
56 |
Correct |
9 ms |
348 KB |
n=500 |
57 |
Correct |
9 ms |
600 KB |
n=500 |
58 |
Correct |
9 ms |
344 KB |
n=500 |
59 |
Correct |
2 ms |
600 KB |
n=2000 |
60 |
Correct |
26 ms |
604 KB |
n=2000 |
61 |
Correct |
26 ms |
752 KB |
n=2000 |
62 |
Correct |
19 ms |
604 KB |
n=2000 |
63 |
Correct |
2 ms |
600 KB |
n=2000 |
64 |
Correct |
25 ms |
668 KB |
n=2000 |
65 |
Correct |
2 ms |
604 KB |
n=2000 |
66 |
Correct |
28 ms |
604 KB |
n=2000 |
67 |
Correct |
3 ms |
604 KB |
n=2000 |
68 |
Correct |
30 ms |
600 KB |
n=2000 |
69 |
Correct |
171 ms |
604 KB |
n=2000 |
70 |
Correct |
171 ms |
716 KB |
n=2000 |
71 |
Correct |
171 ms |
604 KB |
n=2000 |
72 |
Correct |
89 ms |
604 KB |
n=2000 |
73 |
Correct |
87 ms |
600 KB |
n=2000 |
74 |
Correct |
1 ms |
604 KB |
n=1844 |
75 |
Correct |
90 ms |
604 KB |
n=2000 |
76 |
Correct |
91 ms |
848 KB |
n=2000 |
77 |
Correct |
88 ms |
704 KB |
n=2000 |
78 |
Correct |
93 ms |
600 KB |
n=2000 |
79 |
Correct |
1 ms |
604 KB |
n=2000 |
80 |
Correct |
23 ms |
796 KB |
n=2000 |
81 |
Correct |
22 ms |
604 KB |
n=2000 |
82 |
Correct |
1 ms |
600 KB |
n=2000 |
83 |
Correct |
23 ms |
780 KB |
n=2000 |
84 |
Correct |
47 ms |
604 KB |
n=2000 |
85 |
Correct |
45 ms |
600 KB |
n=2000 |
86 |
Correct |
49 ms |
604 KB |
n=2000 |
87 |
Correct |
50 ms |
728 KB |
n=2000 |
88 |
Correct |
160 ms |
600 KB |
n=2000 |
89 |
Correct |
154 ms |
600 KB |
n=2000 |
90 |
Correct |
78 ms |
784 KB |
n=2000 |
91 |
Correct |
135 ms |
1052 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
n=5 |
2 |
Correct |
1 ms |
348 KB |
n=100 |
3 |
Correct |
1 ms |
348 KB |
n=100 |
4 |
Correct |
0 ms |
348 KB |
n=100 |
5 |
Correct |
0 ms |
348 KB |
n=100 |
6 |
Correct |
1 ms |
348 KB |
n=100 |
7 |
Correct |
1 ms |
516 KB |
n=100 |
8 |
Correct |
1 ms |
348 KB |
n=100 |
9 |
Correct |
1 ms |
348 KB |
n=100 |
10 |
Correct |
1 ms |
344 KB |
n=100 |
11 |
Correct |
1 ms |
344 KB |
n=100 |
12 |
Correct |
0 ms |
348 KB |
n=100 |
13 |
Correct |
1 ms |
348 KB |
n=100 |
14 |
Correct |
1 ms |
348 KB |
n=100 |
15 |
Correct |
0 ms |
348 KB |
n=100 |
16 |
Correct |
1 ms |
348 KB |
n=100 |
17 |
Correct |
0 ms |
348 KB |
n=100 |
18 |
Correct |
0 ms |
348 KB |
n=100 |
19 |
Correct |
0 ms |
348 KB |
n=100 |
20 |
Correct |
0 ms |
348 KB |
n=100 |
21 |
Correct |
1 ms |
348 KB |
n=100 |
22 |
Correct |
0 ms |
348 KB |
n=100 |
23 |
Correct |
1 ms |
344 KB |
n=100 |
24 |
Correct |
1 ms |
348 KB |
n=100 |
25 |
Correct |
1 ms |
348 KB |
n=100 |
26 |
Correct |
0 ms |
348 KB |
n=12 |
27 |
Correct |
1 ms |
348 KB |
n=100 |
28 |
Correct |
1 ms |
348 KB |
n=500 |
29 |
Correct |
2 ms |
348 KB |
n=500 |
30 |
Correct |
2 ms |
348 KB |
n=500 |
31 |
Correct |
2 ms |
348 KB |
n=500 |
32 |
Correct |
1 ms |
348 KB |
n=500 |
33 |
Correct |
2 ms |
348 KB |
n=500 |
34 |
Correct |
1 ms |
348 KB |
n=500 |
35 |
Correct |
2 ms |
528 KB |
n=500 |
36 |
Correct |
11 ms |
524 KB |
n=500 |
37 |
Correct |
11 ms |
348 KB |
n=500 |
38 |
Correct |
11 ms |
572 KB |
n=500 |
39 |
Correct |
6 ms |
348 KB |
n=500 |
40 |
Correct |
7 ms |
792 KB |
n=500 |
41 |
Correct |
6 ms |
344 KB |
n=500 |
42 |
Correct |
6 ms |
348 KB |
n=500 |
43 |
Correct |
6 ms |
348 KB |
n=500 |
44 |
Correct |
6 ms |
348 KB |
n=500 |
45 |
Correct |
1 ms |
348 KB |
n=500 |
46 |
Correct |
2 ms |
348 KB |
n=500 |
47 |
Correct |
2 ms |
348 KB |
n=500 |
48 |
Correct |
1 ms |
344 KB |
n=500 |
49 |
Correct |
2 ms |
344 KB |
n=500 |
50 |
Correct |
3 ms |
348 KB |
n=500 |
51 |
Correct |
3 ms |
348 KB |
n=500 |
52 |
Correct |
3 ms |
344 KB |
n=500 |
53 |
Correct |
3 ms |
348 KB |
n=500 |
54 |
Correct |
5 ms |
524 KB |
n=500 |
55 |
Correct |
1 ms |
348 KB |
n=278 |
56 |
Correct |
9 ms |
348 KB |
n=500 |
57 |
Correct |
9 ms |
600 KB |
n=500 |
58 |
Correct |
9 ms |
344 KB |
n=500 |
59 |
Correct |
2 ms |
600 KB |
n=2000 |
60 |
Correct |
26 ms |
604 KB |
n=2000 |
61 |
Correct |
26 ms |
752 KB |
n=2000 |
62 |
Correct |
19 ms |
604 KB |
n=2000 |
63 |
Correct |
2 ms |
600 KB |
n=2000 |
64 |
Correct |
25 ms |
668 KB |
n=2000 |
65 |
Correct |
2 ms |
604 KB |
n=2000 |
66 |
Correct |
28 ms |
604 KB |
n=2000 |
67 |
Correct |
3 ms |
604 KB |
n=2000 |
68 |
Correct |
30 ms |
600 KB |
n=2000 |
69 |
Correct |
171 ms |
604 KB |
n=2000 |
70 |
Correct |
171 ms |
716 KB |
n=2000 |
71 |
Correct |
171 ms |
604 KB |
n=2000 |
72 |
Correct |
89 ms |
604 KB |
n=2000 |
73 |
Correct |
87 ms |
600 KB |
n=2000 |
74 |
Correct |
1 ms |
604 KB |
n=1844 |
75 |
Correct |
90 ms |
604 KB |
n=2000 |
76 |
Correct |
91 ms |
848 KB |
n=2000 |
77 |
Correct |
88 ms |
704 KB |
n=2000 |
78 |
Correct |
93 ms |
600 KB |
n=2000 |
79 |
Correct |
1 ms |
604 KB |
n=2000 |
80 |
Correct |
23 ms |
796 KB |
n=2000 |
81 |
Correct |
22 ms |
604 KB |
n=2000 |
82 |
Correct |
1 ms |
600 KB |
n=2000 |
83 |
Correct |
23 ms |
780 KB |
n=2000 |
84 |
Correct |
47 ms |
604 KB |
n=2000 |
85 |
Correct |
45 ms |
600 KB |
n=2000 |
86 |
Correct |
49 ms |
604 KB |
n=2000 |
87 |
Correct |
50 ms |
728 KB |
n=2000 |
88 |
Correct |
160 ms |
600 KB |
n=2000 |
89 |
Correct |
154 ms |
600 KB |
n=2000 |
90 |
Correct |
78 ms |
784 KB |
n=2000 |
91 |
Correct |
135 ms |
1052 KB |
n=2000 |
92 |
Runtime error |
1 ms |
540 KB |
Execution killed with signal 11 |
93 |
Halted |
0 ms |
0 KB |
- |