Submission #844541

# Submission time Handle Problem Language Result Execution time Memory
844541 2023-09-05T14:00:22 Z vjudge1 Klasika (COCI20_klasika) C++17
33 / 110
5000 ms 12492 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define int long long
 
const int MAXN = 2e5 + 5;

#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    #define OPEN freopen(".in", "r", stdin); \
                 freopen(".out", "w", stdout);
#else
    #define OPEN void(23);
#endif

vector <pair <int, int>> adj[MAXN];
vector <pair <int, int>> radj[MAXN];
int cnt = 2;
int FindAns(int a, int b)
{
    vector <bool> sub(cnt + 5);
    function <void(int)> dfsSub = [&](int node) -> void
    {
        //cerr << node << " ";
        sub[node] = true;
        for(auto &[child, w] : adj[node]) 
            dfsSub(child);

        return;
    };

    dfsSub(b);

    int ans = 0;
    function <void(int, int, int)> dfs = [&](int node, int par, int sum) -> void
    {
        if(sub[node]) ans = max(ans, sum);
        for(auto &[child, w] : adj[node])
            if(child != par) 
                dfs(child, node, sum ^ w);

        for(auto &[child, w] : radj[node])
            if(child != par) 
                dfs(child, node, sum ^ w);
    };

    dfs(a, 0, 0);

    return ans;
}

void solve()
{
    int q; cin >> q;
    for(int i = 1; i <= q; i++)
    {
        string str; int a, b; cin >> str >> a >> b;
        if(str[0] == 'A')
        {
            adj[a].emplace_back(cnt, b);
            radj[cnt].emplace_back(a, b);
            cnt++;
        }
        else
        {
            cout << FindAns(a, b) << "\n";
        }
    }

    return;
}

int32_t main()
{
    OPEN;

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int t = 1; //cin >> t;
    while(t--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9820 KB Output is correct
2 Correct 3 ms 9820 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 3 ms 9820 KB Output is correct
5 Correct 3 ms 9820 KB Output is correct
6 Correct 3 ms 10072 KB Output is correct
7 Correct 3 ms 9816 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Correct 4 ms 9820 KB Output is correct
10 Correct 3 ms 10072 KB Output is correct
11 Correct 3 ms 9820 KB Output is correct
12 Correct 3 ms 9820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9820 KB Output is correct
2 Correct 3 ms 9820 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 3 ms 9820 KB Output is correct
5 Correct 3 ms 9820 KB Output is correct
6 Correct 3 ms 10072 KB Output is correct
7 Correct 3 ms 9816 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Correct 4 ms 9820 KB Output is correct
10 Correct 3 ms 10072 KB Output is correct
11 Correct 3 ms 9820 KB Output is correct
12 Correct 3 ms 9820 KB Output is correct
13 Correct 9 ms 9816 KB Output is correct
14 Correct 10 ms 9820 KB Output is correct
15 Correct 11 ms 10076 KB Output is correct
16 Correct 8 ms 10076 KB Output is correct
17 Correct 7 ms 9820 KB Output is correct
18 Correct 9 ms 9820 KB Output is correct
19 Correct 9 ms 10076 KB Output is correct
20 Correct 7 ms 9816 KB Output is correct
21 Correct 8 ms 9820 KB Output is correct
22 Correct 9 ms 9820 KB Output is correct
23 Correct 9 ms 9820 KB Output is correct
24 Correct 7 ms 9820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5039 ms 12492 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9820 KB Output is correct
2 Correct 3 ms 9820 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 3 ms 9820 KB Output is correct
5 Correct 3 ms 9820 KB Output is correct
6 Correct 3 ms 10072 KB Output is correct
7 Correct 3 ms 9816 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Correct 4 ms 9820 KB Output is correct
10 Correct 3 ms 10072 KB Output is correct
11 Correct 3 ms 9820 KB Output is correct
12 Correct 3 ms 9820 KB Output is correct
13 Correct 9 ms 9816 KB Output is correct
14 Correct 10 ms 9820 KB Output is correct
15 Correct 11 ms 10076 KB Output is correct
16 Correct 8 ms 10076 KB Output is correct
17 Correct 7 ms 9820 KB Output is correct
18 Correct 9 ms 9820 KB Output is correct
19 Correct 9 ms 10076 KB Output is correct
20 Correct 7 ms 9816 KB Output is correct
21 Correct 8 ms 9820 KB Output is correct
22 Correct 9 ms 9820 KB Output is correct
23 Correct 9 ms 9820 KB Output is correct
24 Correct 7 ms 9820 KB Output is correct
25 Execution timed out 5039 ms 12492 KB Time limit exceeded
26 Halted 0 ms 0 KB -