#include <bits/stdc++.h>
#define TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define For(i,a,b) for(int i = a; i <= b; i++)
#define Ford(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define ii pair<int,int>
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define RRH(v) v.resize(unique(all(v)) - v.begin())
using namespace std;
const int  N = 1e6+7;
const int M = 1e9+7;
const ll oo = 3e18;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long GetRandom(long long l, long long r) {
    return uniform_int_distribution<long long> (l, r)(rng);
}
int n, m, q, a[N];
vector <int> g[N];
int h[N], par[20][N];
int timedfs = 0, tin[N], tout[N];
bool isAnc(int u, int v) {
    return ((tin[u] >= tin[v]) && (tin[u] <= tout[v]));
}
void DFS(int u) {
    tin[u] = ++timedfs;
    for (int v: g[u]) {
        if (v == par[0][u]) continue;
        par[0][v] = u;
        h[v] = h[u] + 1;
        DFS(v);
    }
    tout[u] = timedfs;
}
int LCA(int u, int v) {
    if (h[u] < h[v]) swap(u, v);
    for (int i = h[u] - h[v]; i; i -= i& - i) {
        u = par[__builtin_ctz(i)][u];
    }
  //  cout << u << " " << v << '\n';
    if (u == v) return u;
    for (int i = __lg(h[u]); i >= 0; i --) {
        if (par[i][u] != par[i][v]) u = par[i][u], v = par[i][v];
    }
    return par[0][v];
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    #define TASK ""
    if (fopen (".inp", "r")) {
        freopen (".inp", "r", stdin);
        freopen (".out", "w", stdout);
    }
    if(fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }
    cin >> n >> m >> q;
    For (i, 1, n - 1) {
        int x, y; cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    DFS(1);
    for (int j = 1; (1 << j) <= n; j++) For (i, 1, n) par[j][i] = par[j - 1][par[j - 1][i]];
    For (i, 1, m) cin >> a[i];
    while (q--) {
        int t; cin >> t;
        if (t == 2) {
            bool ok = 0;
            int l, r, v; cin >> l >> r >> v;
            for (int i = l; i <= r; i++) {
                int g = a[i];
                for (int j = i; j <= min(i + 1, r); j++) {
                    g = LCA(g, a[j]);
          ///          cout << i << " " << j << " " << g << '\n';
                    if (g == v) {
                        cout << i << " " << j << '\n';
                        ok = 1;
                        break;
                    }
                    if (isAnc(v, g)) break;
                }
                if (ok == 1) break;
            }
            if (ok == 0) cout << -1 << ' ' << -1 << '\n';
        }
        else {
            int pos, v; cin >> pos >> v;
            a[pos] = v;
        }
    }
    cerr << "Time elapsed: " << TIME << " s.\n";
    return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
treearray.cpp: In function 'int main()':
treearray.cpp:62:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         freopen (".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~
treearray.cpp:63:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen (".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
treearray.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |