Submission #895294

# Submission time Handle Problem Language Result Execution time Memory
895294 2023-12-29T17:55:24 Z TahirAliyev Inside information (BOI21_servers) C++17
0 / 100
81 ms 15452 KB
#include <bits/stdc++.h>

#define ll long long
#define oo 1e9
#define pii pair<int, int>

using namespace std;

const int MAX = 12e4 + 4, LOGMAX = 18;
int n, m;
int par[LOGMAX][MAX];
int tin[MAX], tout[MAX];
int h[MAX];
vector<pii> g[MAX];
int dp[MAX][2];
int parl[MAX];

int t = 1;
void dfs(int node, int p){
    par[0][node] = p;
    tin[node] = t++;
    for(pii to : g[node]){
        if(p == to.first) continue;
        h[to.first] = h[node] + 1;
        dp[to.first][0] = node;
        dp[to.first][1] = node;
        if((parl[node] > to.second) || !parl[node]){
            dp[to.first][0] = dp[node][0];
        }
        if((parl[node] < to.second) || !parl[node]){
            dp[to.first][1] = dp[node][1];
        }
        parl[to.first] = to.second; 
        dfs(to.first, node);
    }
    tout[node] = t++;
}

bool isAnc(int u, int v){
    return (tin[u] <= tin[v] && tout[u] >= tout[v]);
}

int lift(int u, int l){
    for(int j = LOGMAX - 1; j >= 0; j--){
        if(!isAnc(par[j][u], l)) u = par[j][u];
    }
    return u;
}
int lca(int u, int v){
    if(isAnc(u, v)) return u;
    if(isAnc(v, u)) return v;  
    return par[0][lift(u, v)];
}


vector<array<int, 3>> Q; 
vector<bool> ans;

int main(){
    cin >> n >> m; 
    for(int i = 1; i <= n + m - 1; i++){
        string s; cin >> s;
        if(s[0] == 'S'){
            int u, v; cin >> u >> v;
            g[u].push_back({v, i});
            g[v].push_back({u, i});
        }
        else{
            int u, a; cin >> u >> a;
            Q.push_back({a, u, i});
        }
    }
    dp[1][0] = 1;
    dp[1][1] = 1;
    dfs(1, 1);
    for(int j = 1; j < LOGMAX; j++){
        for(int i = 1; i <= n; i++){
            par[j][i] = par[j - 1][par[j - 1][i]];
        }
    }
    for(auto a : Q){
        if(a[0] == a[1]){
            ans.push_back(1);
            continue;
        }
        if(parl[lift(a[0], a[1])] > parl[lift(a[1], a[0])] || parl[a[1]] > a[2]){
            ans.push_back(0);
            continue;
        }
        int l = lca(a[0], a[1]);
        if(h[dp[a[0]][1]] >= h[l] && h[dp[a[1]][0]] >= h[l]) ans.push_back(1);
        else ans.push_back(0);
    }
    for(bool i : ans) cout << (i? "yes" : "no") << '\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 81 ms 15396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 81 ms 15396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 66 ms 15424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 66 ms 15424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 15432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 15432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 64 ms 15396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 64 ms 15396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 68 ms 15432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 68 ms 15432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 15452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 15452 KB Output isn't correct
2 Halted 0 ms 0 KB -