Submission #769992

# Submission time Handle Problem Language Result Execution time Memory
769992 2023-06-30T15:52:36 Z vjudge1 Klasika (COCI20_klasika) C++17
33 / 110
93 ms 1080 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define vi vector<int>
#define ve vector
#define ll long long
#define vl vector<ll>
#define vll vector<pair<ll,ll>>
#define onbit __builtin_popcount
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e18
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
using namespace std;
using namespace __gnu_pbds;
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll MOD = 1e9+9;
const int nax = 2e3+5;
const int MAX_VAL = 1e6;
double PI=3.14159265359;
int arx[8]={1,1,0,-1,-1,-1, 0, 1};
int ary[8]={0,1,1, 1, 0,-1,-1,-1};
void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
vii adj[nax];
int parent[nax]; 
bool test=false;
int dis;
int res=0;
int mx=0;
void dfs(int x,int p)
{
    if (test) return;
    for(auto u:adj[x])
    {
        if (u.fi==p) continue;
        if (test) return;
        res^=u.se;
        if (u.fi==dis)
        {
            test=true;
            return;
        }
        dfs(u.fi,x);
        if (test) return;
        res^=u.se;
    }
}
void dfs2(int x,int p)
{
    for(auto u:adj[x])
    {
        if (u.fi==p) continue;
        res^=u.se;
        mx=max(mx,res);
        dfs2(u.fi,x);
        res^=u.se;
    }
}
int main(){
    optimise;
    /*#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif*/
    //setIO("redistricting");
    int q;
    cin>>q;
    int cnt=1;
    parent[0]=-1;
    while(q--)
    {
        string c;
        cin>>c;
        test=false;
        if(c[0]=='A'){
            int x,y;
            cin>>x>>y;
            x--;
            parent[cnt]=x;
            adj[cnt].pb({x,y});
            adj[x].pb({cnt,y});
            cnt++;
        }else{
            int x,y;
            cin>>x>>y;
            x--;y--;
            dis=y;
            res=0;
            if (x!=y) dfs(x,-1);
            mx=res;
            dfs2(y,parent[y]);
            cout<<mx<<endl;
        }
    }
}

Compilation message

klasika.cpp: In function 'void setIO(std::string)':
klasika.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
klasika.cpp:34:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 372 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 368 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 372 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 372 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 368 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 372 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 5 ms 440 KB Output is correct
14 Correct 5 ms 468 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 4 ms 468 KB Output is correct
17 Correct 4 ms 380 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 3 ms 476 KB Output is correct
21 Correct 4 ms 340 KB Output is correct
22 Correct 4 ms 340 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 3 ms 424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 93 ms 1080 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 372 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 368 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 372 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 5 ms 440 KB Output is correct
14 Correct 5 ms 468 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 4 ms 468 KB Output is correct
17 Correct 4 ms 380 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 3 ms 476 KB Output is correct
21 Correct 4 ms 340 KB Output is correct
22 Correct 4 ms 340 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 3 ms 424 KB Output is correct
25 Runtime error 93 ms 1080 KB Execution killed with signal 11
26 Halted 0 ms 0 KB -