답안 #769981

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
769981 2023-06-30T15:36:45 Z vjudge1 Klasika (COCI20_klasika) C++17
33 / 110
5000 ms 4408 KB
//YOU WILL MAKE IT
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+2;
int ans=0;
int col=1;
vector<pair<int,int>> graph[N];
int pa[N];
int vis[N];
void dfs(int i,int j,int p,int cur,bool f){
    if(f||vis[i]==col)
     ans=max(ans,cur);
    for(auto h:graph[i]){
        int x=h.first;
        if((x==p)||(x==pa[j]&&f)) continue;
        dfs(x,j,i,cur^(h.second),(f|(x==j)));
    }
}
void DFS(int i,int p){
    vis[i]=col;
    for(auto h:graph[i]){
        if(h.first!=p){
            DFS(h.first,i);
        }
    }
}
void solve(){
  int q;cin>>q;
  int n=2;
  while(q--){
    string s;cin>>s;
    int x,y;cin>>x>>y;
    if(s[0]=='A'){
        graph[n].push_back({x,y});
        graph[x].push_back({n,y});
        pa[n]=x;
        n++;
    }
    else{
        col++;
        ans=0;
        if(y==1) DFS(y,-1);
        else DFS(y,pa[y]);
        dfs(x,y,-1,0,(x==y));
        cout<<ans<<endl;
    }
  }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
   int t=1;
   // cin>>t;
    while(t--){
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 7 ms 2688 KB Output is correct
14 Correct 7 ms 2724 KB Output is correct
15 Correct 7 ms 2772 KB Output is correct
16 Correct 5 ms 2772 KB Output is correct
17 Correct 6 ms 2644 KB Output is correct
18 Correct 8 ms 2644 KB Output is correct
19 Correct 8 ms 2644 KB Output is correct
20 Correct 6 ms 2644 KB Output is correct
21 Correct 7 ms 2644 KB Output is correct
22 Correct 8 ms 2644 KB Output is correct
23 Correct 9 ms 2728 KB Output is correct
24 Correct 6 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5058 ms 4408 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 7 ms 2688 KB Output is correct
14 Correct 7 ms 2724 KB Output is correct
15 Correct 7 ms 2772 KB Output is correct
16 Correct 5 ms 2772 KB Output is correct
17 Correct 6 ms 2644 KB Output is correct
18 Correct 8 ms 2644 KB Output is correct
19 Correct 8 ms 2644 KB Output is correct
20 Correct 6 ms 2644 KB Output is correct
21 Correct 7 ms 2644 KB Output is correct
22 Correct 8 ms 2644 KB Output is correct
23 Correct 9 ms 2728 KB Output is correct
24 Correct 6 ms 2644 KB Output is correct
25 Execution timed out 5058 ms 4408 KB Time limit exceeded
26 Halted 0 ms 0 KB -