Submission #748054

# Submission time Handle Problem Language Result Execution time Memory
748054 2023-05-25T10:41:48 Z vjudge1 Inside information (BOI21_servers) C++17
53 / 100
180 ms 36492 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn=120000+10;
struct yal{
    int u,v,w;
    int getad(int fu){
        int ret=(fu^u^v);
        return ret;
    }
};

struct quer{
    char c;
    int u,v,w,res;
    quer(){
        res=0;
    }
};
quer allq[maxn];
yal alled[maxn];
vector<int>adj[maxn];
int high[maxn],lca[20][maxn],n,k,now=0,nowq=0,timea=0,par[maxn],dpinc[maxn],dpdec[maxn],val[maxn];
pair<int,int>stf[maxn];

int root(int chi){
    if(chi==par[chi])
    {
        return chi;
    }
    return par[chi]=root(par[chi]);
}

void con(int u,int v){
    int rootu=root(u),rootv=root(v);
    if(rootu!=rootv){
        par[rootu]=rootv;
    }
}

int isc(int u,int v){
    int rootu=root(u),rootv=root(v);
    //cout<<u<<" "<<v<<" "<<rootu<<" "<<rootv<<"\n";
    if(rootu!=rootv){
        return 0;
    }
    return 1;
}

void dfs(int u,int para=0){
    if(u!=1){
        if(val[u]<val[para]){
            dpinc[u]=dpinc[para]+1;
            dpdec[u]=1;
        }
        else{
            dpinc[u]=1;
            dpdec[u]=dpdec[para]+1;
        }
    }
    timea++;
    stf[u].first=timea;
    lca[0][u]=para;
    for(auto x:adj[u]){
        int v=alled[x].getad(u);
        if(v!=para){
            val[v]=alled[x].w;
            high[v]=high[u]+1;
            dfs(v,u);
        }
    }
    stf[u].second=timea;
}

void callca(){
    for(int i=1;i<20;i++){
        for(int j=1;j<=n;j++){
            lca[i][j]=lca[i-1][lca[i-1][j]];
        }
    }
}

bool zird(int u,int v){
    if(stf[v].first<=stf[u].first&&stf[v].second>=stf[u].second){
        return 1;
    }
    return 0;
}

void solve(int ind){
    int u=allq[ind].u,v=allq[ind].v;
    if(zird(u,v)){
        int di=high[u]-high[v];
        if(dpdec[u]>=di){
            return ;
        }
        else{
            allq[ind].res=0;
            return ;
        }
    }
    if(zird(v,u)){
        int di=high[v]-high[u];
        if(dpinc[v]>=di){
            return ;
        }
        else{
            allq[ind].res=0;
            return ;
        }
    }
    int fu=u,fv=v;
    for(int i=19;i>=0;i--){
        if(lca[i][u]!=0&&!zird(v,lca[i][u])){
            u=lca[i][u];
        }   
    }
    u=lca[0][u];
    int di=high[fv]-high[u];
    if(dpinc[fv]<di){
        allq[ind].res=0;
        return ;
    }
    di=high[fu]-high[u];
    if(dpdec[fu]<di){
        allq[ind].res=0;
        return ;
    }
    if(stf[fv].first>stf[fu].first){
        allq[ind].res=0;
    }
};


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    for(int i=1;i<maxn;i++){
        par[i]=i;
    }
    cin>>n>>k;
    for(int i=0;i<n+k-1;i++){
        char c;
        cin>>c;
        if(c=='S'){
            now++;
            cin>>alled[now].u>>alled[now].v;
            alled[now].w=now;
            adj[alled[now].u].push_back(now);
            adj[alled[now].v].push_back(now);
            con(alled[now].u,alled[now].v);
            continue;
        }
        if(c=='Q'){
            nowq++;
            allq[nowq].c=c;
            cin>>allq[nowq].u>>allq[nowq].v;
            allq[nowq].w=now;
            allq[nowq].res=isc(allq[nowq].u,allq[nowq].v);
            continue;
        }
        return 0;
        nowq++;
        allq[nowq].c=c;
        cin>>allq[nowq].u;
        allq[nowq].w=now;
    }
    dfs(1);
    callca();
    for(int i=1;i<=nowq;i++){
        if(allq[i].c=='Q'){
            solve(i); 
            if(allq[i].res==1){
                cout<<"yes\n";
            }
            else{
                cout<<"no\n";
            }
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 31 ms 7240 KB Output is correct
2 Correct 39 ms 8356 KB Output is correct
3 Correct 37 ms 8384 KB Output is correct
4 Correct 43 ms 8392 KB Output is correct
5 Correct 30 ms 8672 KB Output is correct
6 Correct 32 ms 8396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 7240 KB Output is correct
2 Correct 39 ms 8356 KB Output is correct
3 Correct 37 ms 8384 KB Output is correct
4 Correct 43 ms 8392 KB Output is correct
5 Correct 30 ms 8672 KB Output is correct
6 Correct 32 ms 8396 KB Output is correct
7 Partially correct 4 ms 5984 KB Output is incorrect
8 Partially correct 3 ms 5988 KB Output is incorrect
9 Partially correct 4 ms 6120 KB Output is incorrect
10 Partially correct 3 ms 5988 KB Output is incorrect
11 Partially correct 4 ms 5972 KB Output is incorrect
12 Partially correct 3 ms 5972 KB Output is incorrect
# Verdict Execution time Memory Grader output
1 Correct 26 ms 7360 KB Output is correct
2 Correct 119 ms 27064 KB Output is correct
3 Correct 122 ms 27060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 7360 KB Output is correct
2 Correct 119 ms 27064 KB Output is correct
3 Correct 122 ms 27060 KB Output is correct
4 Partially correct 4 ms 5984 KB Output is incorrect
5 Partially correct 3 ms 5908 KB Output is incorrect
6 Partially correct 4 ms 5972 KB Output is incorrect
7 Partially correct 5 ms 5972 KB Output is incorrect
# Verdict Execution time Memory Grader output
1 Correct 24 ms 7244 KB Output is correct
2 Correct 119 ms 36464 KB Output is correct
3 Correct 111 ms 36440 KB Output is correct
4 Correct 80 ms 36376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 7244 KB Output is correct
2 Correct 119 ms 36464 KB Output is correct
3 Correct 111 ms 36440 KB Output is correct
4 Correct 80 ms 36376 KB Output is correct
5 Partially correct 3 ms 5972 KB Output is incorrect
6 Partially correct 3 ms 5972 KB Output is incorrect
7 Partially correct 3 ms 5972 KB Output is incorrect
8 Partially correct 3 ms 5988 KB Output is incorrect
9 Partially correct 3 ms 5972 KB Output is incorrect
# Verdict Execution time Memory Grader output
1 Correct 27 ms 7212 KB Output is correct
2 Correct 105 ms 26944 KB Output is correct
3 Correct 128 ms 26956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 7212 KB Output is correct
2 Correct 105 ms 26944 KB Output is correct
3 Correct 128 ms 26956 KB Output is correct
4 Partially correct 3 ms 5972 KB Output is incorrect
5 Partially correct 3 ms 5972 KB Output is incorrect
6 Partially correct 25 ms 10188 KB Output is incorrect
# Verdict Execution time Memory Grader output
1 Correct 24 ms 7244 KB Output is correct
2 Correct 112 ms 36432 KB Output is correct
3 Correct 109 ms 36412 KB Output is correct
4 Correct 78 ms 36296 KB Output is correct
5 Correct 26 ms 7244 KB Output is correct
6 Correct 107 ms 26980 KB Output is correct
7 Correct 123 ms 26928 KB Output is correct
8 Correct 179 ms 27540 KB Output is correct
9 Correct 161 ms 27548 KB Output is correct
10 Correct 126 ms 30532 KB Output is correct
11 Correct 180 ms 29800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 7244 KB Output is correct
2 Correct 112 ms 36432 KB Output is correct
3 Correct 109 ms 36412 KB Output is correct
4 Correct 78 ms 36296 KB Output is correct
5 Correct 26 ms 7244 KB Output is correct
6 Correct 107 ms 26980 KB Output is correct
7 Correct 123 ms 26928 KB Output is correct
8 Correct 179 ms 27540 KB Output is correct
9 Correct 161 ms 27548 KB Output is correct
10 Correct 126 ms 30532 KB Output is correct
11 Correct 180 ms 29800 KB Output is correct
12 Partially correct 3 ms 5972 KB Output is incorrect
13 Partially correct 3 ms 5932 KB Output is incorrect
14 Partially correct 3 ms 5972 KB Output is incorrect
15 Partially correct 3 ms 5844 KB Output is incorrect
16 Partially correct 4 ms 5868 KB Output is incorrect
17 Partially correct 3 ms 5972 KB Output is incorrect
18 Partially correct 3 ms 5972 KB Output is incorrect
19 Partially correct 39 ms 9296 KB Output is incorrect
20 Partially correct 3 ms 5844 KB Output is incorrect
21 Partially correct 3 ms 5972 KB Output is incorrect
22 Partially correct 3 ms 5844 KB Output is incorrect
23 Partially correct 34 ms 9368 KB Output is incorrect
24 Partially correct 50 ms 10072 KB Output is incorrect
# Verdict Execution time Memory Grader output
1 Correct 26 ms 7240 KB Output is correct
2 Correct 38 ms 8400 KB Output is correct
3 Correct 36 ms 8396 KB Output is correct
4 Correct 43 ms 8408 KB Output is correct
5 Correct 29 ms 8780 KB Output is correct
6 Correct 33 ms 8388 KB Output is correct
7 Correct 25 ms 7356 KB Output is correct
8 Correct 124 ms 27012 KB Output is correct
9 Correct 120 ms 26968 KB Output is correct
10 Correct 23 ms 7248 KB Output is correct
11 Correct 110 ms 36492 KB Output is correct
12 Correct 103 ms 36444 KB Output is correct
13 Correct 76 ms 36344 KB Output is correct
14 Correct 26 ms 7244 KB Output is correct
15 Correct 99 ms 26984 KB Output is correct
16 Correct 112 ms 26944 KB Output is correct
17 Correct 156 ms 27548 KB Output is correct
18 Correct 142 ms 27488 KB Output is correct
19 Correct 129 ms 30488 KB Output is correct
20 Correct 159 ms 29792 KB Output is correct
21 Correct 124 ms 27460 KB Output is correct
22 Correct 114 ms 27540 KB Output is correct
23 Correct 162 ms 27708 KB Output is correct
24 Correct 142 ms 27676 KB Output is correct
25 Correct 174 ms 29944 KB Output is correct
26 Correct 112 ms 27228 KB Output is correct
27 Correct 106 ms 27340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 7240 KB Output is correct
2 Correct 38 ms 8400 KB Output is correct
3 Correct 36 ms 8396 KB Output is correct
4 Correct 43 ms 8408 KB Output is correct
5 Correct 29 ms 8780 KB Output is correct
6 Correct 33 ms 8388 KB Output is correct
7 Correct 25 ms 7356 KB Output is correct
8 Correct 124 ms 27012 KB Output is correct
9 Correct 120 ms 26968 KB Output is correct
10 Correct 23 ms 7248 KB Output is correct
11 Correct 110 ms 36492 KB Output is correct
12 Correct 103 ms 36444 KB Output is correct
13 Correct 76 ms 36344 KB Output is correct
14 Correct 26 ms 7244 KB Output is correct
15 Correct 99 ms 26984 KB Output is correct
16 Correct 112 ms 26944 KB Output is correct
17 Correct 156 ms 27548 KB Output is correct
18 Correct 142 ms 27488 KB Output is correct
19 Correct 129 ms 30488 KB Output is correct
20 Correct 159 ms 29792 KB Output is correct
21 Correct 124 ms 27460 KB Output is correct
22 Correct 114 ms 27540 KB Output is correct
23 Correct 162 ms 27708 KB Output is correct
24 Correct 142 ms 27676 KB Output is correct
25 Correct 174 ms 29944 KB Output is correct
26 Correct 112 ms 27228 KB Output is correct
27 Correct 106 ms 27340 KB Output is correct
28 Partially correct 3 ms 5972 KB Output is incorrect
29 Partially correct 3 ms 5972 KB Output is incorrect
30 Partially correct 4 ms 6100 KB Output is incorrect
31 Partially correct 3 ms 5972 KB Output is incorrect
32 Partially correct 4 ms 5844 KB Output is incorrect
33 Partially correct 3 ms 5972 KB Output is incorrect
34 Partially correct 3 ms 5972 KB Output is incorrect
35 Partially correct 3 ms 5844 KB Output is incorrect
36 Partially correct 3 ms 5844 KB Output is incorrect
37 Partially correct 3 ms 5844 KB Output is incorrect
38 Partially correct 3 ms 5972 KB Output is incorrect
39 Partially correct 3 ms 5972 KB Output is incorrect
40 Partially correct 3 ms 5844 KB Output is incorrect
41 Partially correct 3 ms 5844 KB Output is incorrect
42 Partially correct 3 ms 5972 KB Output is incorrect
43 Partially correct 3 ms 5972 KB Output is incorrect
44 Partially correct 3 ms 5928 KB Output is incorrect
45 Partially correct 29 ms 9184 KB Output is incorrect
46 Partially correct 3 ms 5844 KB Output is incorrect
47 Partially correct 3 ms 5972 KB Output is incorrect
48 Partially correct 3 ms 5844 KB Output is incorrect
49 Partially correct 35 ms 9416 KB Output is incorrect
50 Partially correct 42 ms 10112 KB Output is incorrect
51 Partially correct 3 ms 5972 KB Output is incorrect
52 Partially correct 4 ms 5876 KB Output is incorrect
53 Partially correct 3 ms 5844 KB Output is incorrect
54 Partially correct 3 ms 5972 KB Output is incorrect
55 Partially correct 4 ms 5844 KB Output is incorrect
56 Partially correct 3 ms 5972 KB Output is incorrect
57 Partially correct 3 ms 5972 KB Output is incorrect
58 Partially correct 41 ms 9940 KB Output is incorrect
59 Partially correct 48 ms 11148 KB Output is incorrect