이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define LL long long
#define Kultivator ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const LL Mxn = 1e6 + 7;
const LL Mod = 1e9 + 7;
const LL Inf = 1e14 + 7;
vector <int> g[Mxn];
int F[Mxn], A[Mxn];
int N, M, Q;
void Dfs(int v, int p){
F[v] = p;
for(auto i : g[v]){
if(i == p) continue;
Dfs(i, v);
}
}
void Check(int v, int B, bool &Ans, vector <bool> &Used){
if(v == -1) return;
if(Used[v]){
if(v == B) Ans = true;
return;
}
Used[v] = true;
Check(F[v], B, Ans, Used);
}
int main(){
Kultivator;
cin >> N >> M >> Q;
for(int i = 1, L, R; i < N; i++){
cin >> L >> R;
g[L].pb(R);
g[R].pb(L);
}
Dfs(1, -1);
for(int i = 1; i <= M; i++){
cin >> A[i];
}
while(Q--){
int T;
cin >> T;
if(T == 1){
int Pos, Id;
cin >> Pos >> Id;
A[Pos] = Id;
} else {
int L, R, V;
pair <int, int> Ans = {-1, -1};
cin >> L >> R >> V;
for(int i = L; i < R; i++){
if(A[i] == V){
Ans.first = Ans.second = i;
break;
}
bool W = false;
vector <bool> Used(N + 1, false);
Check(A[i], V, W, Used);
Check(A[i + 1], V, W, Used);
if(W){
Ans.first = i;
Ans.second = i + 1;
break;
}
}
if(A[R] == V) Ans.first = Ans.second = R;
cout << Ans.first << ' ' << Ans.second << '\n';
}
}
}
# | 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... |