Submission #769975

# Submission time Handle Problem Language Result Execution time Memory
769975 2023-06-30T15:32:50 Z vjudge1 Klasika (COCI20_klasika) C++17
33 / 110
5000 ms 6996 KB
#include <bits/stdc++.h>
#define ve vector
#define vi vector<int>
#define vii vector<ii>
#define ii pair<int,int>
#define fi first
#define se second
#define ll long long
#define INF 1e9+7
#define pb push_back
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;
const int MOD = 1e9+7;
const int nax = 2e5+5;
void readio(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
vii adj[nax];
int cnt = 0, tin[nax], tout[nax];
bool isAnc(int u, int v){
    return (tin[u] <= tin[v] && tout[v] <= tout[u]);
}
void dfs(int u, int p){
    tin[u] = cnt++;
    for(auto x : adj[u]){
        if(x.fi == p ) continue;
        dfs(x.fi,u);
    }
    tout[u] = cnt++;
}
int srch(int u, int p,int cst, int sub){
    int mx = 0;
    if(isAnc(sub, u)) {
        //cout << u << endl;
        mx = cst;
    }
    for(auto x : adj[u]){
        if(x.fi == p) continue;
        mx = max(srch(x.fi,u, cst^x.se, sub), mx);
    } 
    return mx;
}
int main()
{
    optimise;
    int q;
    cin >> q;
    int cur = 0;
    while(q--)
    {
        string type;
        cin >> type;
        if(type == "Add"){
            int x,y;
            cin >> x >> y;
            x--;
            cur++;
            adj[x].pb({cur,y});
            adj[cur].pb({x,y});
        } else {
            int a,b;
            cin >> a >> b;
            a--,b--;
            cnt = 0;
            dfs(0,0);
            cout << srch(a, -1, 0, b) << endl; 
        }
        
    }
}

Compilation message

klasika.cpp: In function 'void readio()':
klasika.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
klasika.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 5024 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 4948 KB Output is correct
6 Correct 3 ms 5028 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 5024 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 5028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 5024 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 4948 KB Output is correct
6 Correct 3 ms 5028 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 5024 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 5028 KB Output is correct
13 Correct 9 ms 5084 KB Output is correct
14 Correct 10 ms 5108 KB Output is correct
15 Correct 10 ms 5204 KB Output is correct
16 Correct 7 ms 5204 KB Output is correct
17 Correct 8 ms 5076 KB Output is correct
18 Correct 10 ms 5076 KB Output is correct
19 Correct 10 ms 5032 KB Output is correct
20 Correct 8 ms 5076 KB Output is correct
21 Correct 12 ms 5032 KB Output is correct
22 Correct 10 ms 5040 KB Output is correct
23 Correct 10 ms 5040 KB Output is correct
24 Correct 8 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5033 ms 6996 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 5024 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 4948 KB Output is correct
6 Correct 3 ms 5028 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 5024 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 5028 KB Output is correct
13 Correct 9 ms 5084 KB Output is correct
14 Correct 10 ms 5108 KB Output is correct
15 Correct 10 ms 5204 KB Output is correct
16 Correct 7 ms 5204 KB Output is correct
17 Correct 8 ms 5076 KB Output is correct
18 Correct 10 ms 5076 KB Output is correct
19 Correct 10 ms 5032 KB Output is correct
20 Correct 8 ms 5076 KB Output is correct
21 Correct 12 ms 5032 KB Output is correct
22 Correct 10 ms 5040 KB Output is correct
23 Correct 10 ms 5040 KB Output is correct
24 Correct 8 ms 5076 KB Output is correct
25 Execution timed out 5033 ms 6996 KB Time limit exceeded
26 Halted 0 ms 0 KB -