이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long ll;
#define trav(a, b) for(auto a : b)
#define v vector
#define vl vector<ll>
#define mk make_pair
#define f first
#define s second
using namespace std;
vector<pair<int, int>> adj[2000];
int vis[2000];
int crr;
void ff(int x, int pr, bool flag){
if(x == crr)flag = true;
if(flag){
vis[x] = 1;
}
trav(e, adj[x]){
if(e.f != pr)ff(e.f, x, flag);
}
}
int ans = 0;
void dfs(int x, int pr, int level){
if(vis[x])
ans = max(ans, level);
trav(e, adj[x]){
if(e.f != pr){
dfs(e.f, x, level ^ e.s);
}
}
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int q;
cin >> q;
string x;
int a, b, size = 1;
while(q --){
cin >> x >> a >> b;
if(x == "Add"){
adj[a - 1].push_back(mk(size, b));
adj[size].push_back(mk(a - 1, b));
size ++;
} else {
crr = b - 1;
for(int i = 0;i < size;i ++)vis[i] = 0;
ff(0, -1, false);
ans = 0;
dfs(a - 1, -1, 0);
cout << ans << '\n';
}
}
return 0;
}
# | 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... |