/* Speech to the young */
#include <bits/stdc++.h>
#define endl "\n"
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz size()
#define rep(i,k,n) for(int i = k ; i <= n ; ++i)
#define per(i,k,n) for(int i = k ; i >= n ; --i)
#define Zymraq() ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) x.begin(),x.end()
#define fr(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define toqta return 0
#define PERMUTE next_permutation
#define no cout<<"NO"<<endl;
#define yes cout<<"YES"<<endl;
using namespace std;
typedef long long ull;
typedef unsigned long long ll;
typedef string S;
typedef double D;
const int N = 1e6 + 17;
const int modd = 1e9 + 7;
const int INF = 2e9 - 19;
const int P = 37;
const ll NN = 1e7 + 17;
const D eps = 1e-19;
const double pi = 3.141592653589793238462643383279 ;
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b){
return (a.second < b.second);
}
void pre (ll a) {
cout << fixed << setprecision(a);
return;
}
ll n, m, q, a[N];
vector <ll> gg[N];
vector <ll> g[N];
ll col[N];
ll l, r, prd;
void get (ll v) {
for (int i = 0; i < g[v].size(); ++ i) {
ll to = g[v][i];
if (prd == v) {
col[to] = i + 1;
// cout << to << ' ' << col[to] << '\n';
} else {
col[to] = col[v];
}
get (to);
}
return;
}
ll timer = 0;
ll coll[N];
void up (ll v) {
if (v == prd) return;
coll[v] = timer;
timer ++;
// cout << v << ' ';
for (auto to: gg[v]) {
up(to);
}
}
int main(){
cin >> n >> m >> q;
for (int i = 1; i < n; ++ i) {
ll x, y;
cin >> x >> y;
g[min (x, y)].pb(max (x, y));
gg[max(x, y)].pb (min(x, y));
}
for (int i = 1; i <= m; ++ i) {
cin >> a[i];
}
while (q --) {
ll type;
cin >> type;
if (type == 1) {
ll pos, val;
cin >> pos >> val;
a[pos] = val;
}
if (type == 2) {
cin >> l >> r >> prd;
bool ok = 0;
for (int i = l; i <= r; ++ i) {
if (a[i] == prd) {
cout << i << ' ' << i << '\n';
ok = 1;
break;
}
}
if (ok) continue;
get (prd);
for (int i = l; i < r; ++ i) {
for (int j = i + 1; j <= r; ++ j) {
set <ll> s;
for (int k = i; k <= j; ++ k) {
s.insert (col[a[k]]);
}
if (s.size() >= 2) {
cout << i << ' ' << r << '\n';
ok = 1;
}
if (ok) break;
set <ll> ss;
ll mx = 0;
for (int k = i; k <= j; ++ k) {
ss.insert (a[k]);
mx = max (mx, a[k]);
}
if (ss.size() == 1) continue;
timer = 1;
up(mx);
s.clear();
for (int k = i; k <= j; ++ k) {
if (coll[a[k]] == 0) continue;
s.insert(coll[a[k]]);
}
if (s.size() == ss.size()) {
cout << i << ' ' << j << '\n';
ok = 1;
}
for (int k = 1; k <= n; ++ k) coll[k] = 0;
if (ok) break;
}
if (ok) break;
}
for (int i = 1; i <= n; ++ i) col[i] = 0;
if (ok) continue;
cout << -1 << ' ' << -1 << '\n';
}
}
return 0;
}
/*
5 4 4
1 2
3 1
3 4
5 3
4 5 2 3
2 1 3 1
1 3 5
2 3 4 5
2 1 3 1
*/
Compilation message
treearray.cpp: In function 'void get(ll)':
treearray.cpp:53:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long unsigned int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int i = 0; i < g[v].size(); ++ i) {
| ~~^~~~~~~~~~~~~
treearray.cpp: In function 'int main()':
treearray.cpp:81:20: warning: comparison of integer expressions of different signedness: 'int' and 'll' {aka 'long long unsigned int'} [-Wsign-compare]
81 | for (int i = 1; i < n; ++ i) {
| ~~^~~
treearray.cpp:87:20: warning: comparison of integer expressions of different signedness: 'int' and 'll' {aka 'long long unsigned int'} [-Wsign-compare]
87 | for (int i = 1; i <= m; ++ i) {
| ~~^~~~
treearray.cpp:101:22: warning: comparison of integer expressions of different signedness: 'int' and 'll' {aka 'long long unsigned int'} [-Wsign-compare]
101 | for (int i = l; i <= r; ++ i) {
| ~~^~~~
treearray.cpp:110:22: warning: comparison of integer expressions of different signedness: 'int' and 'll' {aka 'long long unsigned int'} [-Wsign-compare]
110 | for (int i = l; i < r; ++ i) {
| ~~^~~
treearray.cpp:111:27: warning: comparison of integer expressions of different signedness: 'int' and 'll' {aka 'long long unsigned int'} [-Wsign-compare]
111 | for (int j = i + 1; j <= r; ++ j) {
| ~~^~~~
treearray.cpp:139:24: warning: comparison of integer expressions of different signedness: 'int' and 'll' {aka 'long long unsigned int'} [-Wsign-compare]
139 | for (int k = 1; k <= n; ++ k) coll[k] = 0;
| ~~^~~~
treearray.cpp:145:22: warning: comparison of integer expressions of different signedness: 'int' and 'll' {aka 'long long unsigned int'} [-Wsign-compare]
145 | for (int i = 1; i <= n; ++ i) col[i] = 0;
| ~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
47256 KB |
n=5 |
2 |
Incorrect |
31 ms |
47208 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
47256 KB |
n=5 |
2 |
Incorrect |
31 ms |
47208 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
47256 KB |
n=5 |
2 |
Incorrect |
31 ms |
47208 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
47256 KB |
n=5 |
2 |
Incorrect |
31 ms |
47208 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |