/// tree bends in youth
/// 24 .10.2023
/// success is doing same thing in every single day!!!
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
using namespace std;
const ll N =100+ 5;
const ll NN =2e6 + 5;
const ll INF = -1e1;
const ll MOD = 1e9 + 7;
const ll LG = 18;
const ll k = 316;
vector <int> g[501];
int tin[N],tout[N],a[N],cnt,used[N];
int p[N][16];
void dfs(int v){
cnt++;
used[v] = 1;
tin[v] = cnt;
for(int to : g[v]){
if(used[to] == 0){
p[to][0] = v;
dfs(to);
}
}
tout[v] = cnt;
}
bool upper(int x,int y){
if(tin[x] <= tin[y] && tout[x] >= tout[y])return 1;
else return 0;
}
int lca(int x,int y){
if(upper(x,y) == 1){
return x;
}
if(upper(y,x) == 1){
return y;
}
for(int j = 6;j >= 0;j--){
int h = p[x][j];
if(upper(h,y) == 0){
x = h;
}
}
return p[x][0];
}
void solve(){
int n,m,q;
cin >> n >> m >> q;
for(int i = 1;i < n;i++){
int u,v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
p[1][0] = 1;
dfs(1);
for(int i = 1;i <= 6;i++){
for(int j = 1;j <= n;j++){
p[j][i] = p[p[j][i - 1]][i - 1];
}
}
for(int i = 1;i <= m;i++){
cin >> a[i];
}
bool was = 1;
while(q--){
int tp,l,r,x;
cin >> tp >> l >> r;
if(tp == 1){
a[l] = r;
}
else{
cin >> x;
bool ok = 0;
for(int j = l;j <= r;j++){
int lc = a[j];
if(lc == x){
cout << j << " " << j << '\n';
ok = 1;
break;
}
int i = j + 1;
while(i <= r){
int lcc= lca(lc,a[i]);
if(lcc == x){
cout << j << ' ' << i << '\n';
ok = 1;
break;
}
lc = lcc;
i++;
}
if(ok)break;
}
if(!ok)cout << "-1 -1\n";
was = 0;
}
}
}
main (){
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ll abd= 1;
// cin >> abd;
for(ll i = 1;i <= abd;i++){
// cout << "Case " << i << ":\n";
solve();
}
}
Compilation message
treearray.cpp: In function 'void solve()':
treearray.cpp:71:10: warning: variable 'was' set but not used [-Wunused-but-set-variable]
71 | bool was = 1;
| ^~~
treearray.cpp: At global scope:
treearray.cpp:107:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
107 | main (){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=5 |
2 |
Correct |
0 ms |
348 KB |
n=100 |
3 |
Correct |
0 ms |
344 KB |
n=100 |
4 |
Correct |
1 ms |
348 KB |
n=100 |
5 |
Correct |
1 ms |
348 KB |
n=100 |
6 |
Correct |
1 ms |
348 KB |
n=100 |
7 |
Correct |
2 ms |
344 KB |
n=100 |
8 |
Correct |
1 ms |
348 KB |
n=100 |
9 |
Correct |
0 ms |
344 KB |
n=100 |
10 |
Correct |
1 ms |
348 KB |
n=100 |
11 |
Correct |
1 ms |
348 KB |
n=100 |
12 |
Correct |
1 ms |
348 KB |
n=100 |
13 |
Correct |
1 ms |
344 KB |
n=100 |
14 |
Correct |
1 ms |
348 KB |
n=100 |
15 |
Correct |
0 ms |
344 KB |
n=100 |
16 |
Correct |
0 ms |
348 KB |
n=100 |
17 |
Correct |
0 ms |
348 KB |
n=100 |
18 |
Correct |
1 ms |
348 KB |
n=100 |
19 |
Correct |
0 ms |
348 KB |
n=100 |
20 |
Correct |
0 ms |
344 KB |
n=100 |
21 |
Correct |
0 ms |
348 KB |
n=100 |
22 |
Correct |
1 ms |
348 KB |
n=100 |
23 |
Correct |
1 ms |
344 KB |
n=100 |
24 |
Correct |
1 ms |
344 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 |
0 ms |
348 KB |
n=5 |
2 |
Correct |
0 ms |
348 KB |
n=100 |
3 |
Correct |
0 ms |
344 KB |
n=100 |
4 |
Correct |
1 ms |
348 KB |
n=100 |
5 |
Correct |
1 ms |
348 KB |
n=100 |
6 |
Correct |
1 ms |
348 KB |
n=100 |
7 |
Correct |
2 ms |
344 KB |
n=100 |
8 |
Correct |
1 ms |
348 KB |
n=100 |
9 |
Correct |
0 ms |
344 KB |
n=100 |
10 |
Correct |
1 ms |
348 KB |
n=100 |
11 |
Correct |
1 ms |
348 KB |
n=100 |
12 |
Correct |
1 ms |
348 KB |
n=100 |
13 |
Correct |
1 ms |
344 KB |
n=100 |
14 |
Correct |
1 ms |
348 KB |
n=100 |
15 |
Correct |
0 ms |
344 KB |
n=100 |
16 |
Correct |
0 ms |
348 KB |
n=100 |
17 |
Correct |
0 ms |
348 KB |
n=100 |
18 |
Correct |
1 ms |
348 KB |
n=100 |
19 |
Correct |
0 ms |
348 KB |
n=100 |
20 |
Correct |
0 ms |
344 KB |
n=100 |
21 |
Correct |
0 ms |
348 KB |
n=100 |
22 |
Correct |
1 ms |
348 KB |
n=100 |
23 |
Correct |
1 ms |
344 KB |
n=100 |
24 |
Correct |
1 ms |
344 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 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=5 |
2 |
Correct |
0 ms |
348 KB |
n=100 |
3 |
Correct |
0 ms |
344 KB |
n=100 |
4 |
Correct |
1 ms |
348 KB |
n=100 |
5 |
Correct |
1 ms |
348 KB |
n=100 |
6 |
Correct |
1 ms |
348 KB |
n=100 |
7 |
Correct |
2 ms |
344 KB |
n=100 |
8 |
Correct |
1 ms |
348 KB |
n=100 |
9 |
Correct |
0 ms |
344 KB |
n=100 |
10 |
Correct |
1 ms |
348 KB |
n=100 |
11 |
Correct |
1 ms |
348 KB |
n=100 |
12 |
Correct |
1 ms |
348 KB |
n=100 |
13 |
Correct |
1 ms |
344 KB |
n=100 |
14 |
Correct |
1 ms |
348 KB |
n=100 |
15 |
Correct |
0 ms |
344 KB |
n=100 |
16 |
Correct |
0 ms |
348 KB |
n=100 |
17 |
Correct |
0 ms |
348 KB |
n=100 |
18 |
Correct |
1 ms |
348 KB |
n=100 |
19 |
Correct |
0 ms |
348 KB |
n=100 |
20 |
Correct |
0 ms |
344 KB |
n=100 |
21 |
Correct |
0 ms |
348 KB |
n=100 |
22 |
Correct |
1 ms |
348 KB |
n=100 |
23 |
Correct |
1 ms |
344 KB |
n=100 |
24 |
Correct |
1 ms |
344 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 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=5 |
2 |
Correct |
0 ms |
348 KB |
n=100 |
3 |
Correct |
0 ms |
344 KB |
n=100 |
4 |
Correct |
1 ms |
348 KB |
n=100 |
5 |
Correct |
1 ms |
348 KB |
n=100 |
6 |
Correct |
1 ms |
348 KB |
n=100 |
7 |
Correct |
2 ms |
344 KB |
n=100 |
8 |
Correct |
1 ms |
348 KB |
n=100 |
9 |
Correct |
0 ms |
344 KB |
n=100 |
10 |
Correct |
1 ms |
348 KB |
n=100 |
11 |
Correct |
1 ms |
348 KB |
n=100 |
12 |
Correct |
1 ms |
348 KB |
n=100 |
13 |
Correct |
1 ms |
344 KB |
n=100 |
14 |
Correct |
1 ms |
348 KB |
n=100 |
15 |
Correct |
0 ms |
344 KB |
n=100 |
16 |
Correct |
0 ms |
348 KB |
n=100 |
17 |
Correct |
0 ms |
348 KB |
n=100 |
18 |
Correct |
1 ms |
348 KB |
n=100 |
19 |
Correct |
0 ms |
348 KB |
n=100 |
20 |
Correct |
0 ms |
344 KB |
n=100 |
21 |
Correct |
0 ms |
348 KB |
n=100 |
22 |
Correct |
1 ms |
348 KB |
n=100 |
23 |
Correct |
1 ms |
344 KB |
n=100 |
24 |
Correct |
1 ms |
344 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 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
29 |
Halted |
0 ms |
0 KB |
- |