/* 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 nears[N];
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;
for (auto to: g[prd]) {
nears[to] = 1;
}
for (int k = i; k <= j; ++ k) {
if (nears[a[k]]) {
cout << i << ' ' << j << '\n';
ok = 1;
break;
}
}
for (int i = 1; i <= n; ++ i) nears[i] = 0;
}
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
sequence.cpp: In function 'void get(ll)':
sequence.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) {
| ~~^~~~~~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:70:20: warning: comparison of integer expressions of different signedness: 'int' and 'll' {aka 'long long unsigned int'} [-Wsign-compare]
70 | for (int i = 1; i < n; ++ i) {
| ~~^~~
sequence.cpp:76:20: warning: comparison of integer expressions of different signedness: 'int' and 'll' {aka 'long long unsigned int'} [-Wsign-compare]
76 | for (int i = 1; i <= m; ++ i) {
| ~~^~~~
sequence.cpp:90:22: warning: comparison of integer expressions of different signedness: 'int' and 'll' {aka 'long long unsigned int'} [-Wsign-compare]
90 | for (int i = l; i <= r; ++ i) {
| ~~^~~~
sequence.cpp:99:22: warning: comparison of integer expressions of different signedness: 'int' and 'll' {aka 'long long unsigned int'} [-Wsign-compare]
99 | for (int i = l; i < r; ++ i) {
| ~~^~~
sequence.cpp:100:27: warning: comparison of integer expressions of different signedness: 'int' and 'll' {aka 'long long unsigned int'} [-Wsign-compare]
100 | for (int j = i + 1; j <= r; ++ j) {
| ~~^~~~
sequence.cpp:120:24: warning: comparison of integer expressions of different signedness: 'int' and 'll' {aka 'long long unsigned int'} [-Wsign-compare]
120 | for (int i = 1; i <= n; ++ i) nears[i] = 0;
| ~~^~~~
sequence.cpp:125:22: warning: comparison of integer expressions of different signedness: 'int' and 'll' {aka 'long long unsigned int'} [-Wsign-compare]
125 | for (int i = 1; i <= n; ++ i) col[i] = 0;
| ~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
47164 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
47180 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
47180 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
47256 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
47164 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
47164 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
47164 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |