UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#214836#2642. colorerican01172ms30128kbC++112.5kb2024-11-22 18:50:372024-11-22 23:10:31

answer

/*  Erica N  */
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define int long long
#define ull unsigned long long
#define pii pair<int, int>
#define ps second
#define pf first
#define itn int
#define rd read()
int read(){
    int xx = 0, ff = 1;char ch = getchar();
    while (ch < '0' || ch > '9') {if (ch == '-')ff = -1; ch = getchar();}
    while (ch >= '0' && ch <= '9')xx = xx * 10 + (ch - '0'), ch = getchar();
    return xx * ff;
}
// void write(int out) {
// 	if (out < 0)
// 		putchar('-'), out = -out;
// 	if (out > 9)
// 		write(out / 10);
// 	putchar(out % 10 + '0');
// }
#define cdbg(x...) do { cerr << #x << " -> "; err(x); } while (0)
void err() { cerr << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cerr << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }


const int N = 3e5 + 5;
const int INF = 1e18;
const int M = 1e7;
const int MOD = 1e9 + 7;


vector<int> e[N];
void add(int a,int b){
    e[a].pb(b);
    e[b].pb(a);
}

string s;


namespace LCA{
    int fa[N][22];
    int dep[N];
    int c[N];
    void dfs(int x,int f){
        c[x]=c[f];
        if(s[x]=='H')c[x]++;
        dep[x]=dep[f]+1;
        for(auto v:e[x]){
            if(v==f)continue;
            fa[v][0]=x;
            for(int i=1;i<=20;i++){
                fa[v][i]=fa[fa[v][i-1]][i-1];
            }
            dfs(v,x);
        }
    }

    int lca(int a,int b){
        if(dep[a]<dep[b])swap(a,b);
        for(int i=20;~i;i--){
            if(dep[fa[a][i]]>=dep[b])a=fa[a][i];
        }
        if(a==b)return a;
        for(int i=20;~i;i--){
            if(fa[a][i]!=fa[b][i]){
                a=fa[a][i];
                b=fa[b][i];
            }
        }

        return fa[a][0];
    }
}using namespace LCA;



signed main() {
    // freopen(".in","r",stdin);
    // freopen(".out","w",stdout);

    int n=rd,m=rd;
    cin>>s;
    s=" "+s;
    for(int i=1;i<n;i++){
        add(rd,rd);
    }


    dfs(1,0);


    while(m--){
        int a=rd,b=rd;
        int anc=lca(a,b);
        int g=c[a]-c[fa[anc][0]]+c[b]-c[anc];
        int l=dep[a]-dep[anc]-dep[b]-dep[anc]+1;
        char op;
        cin>>op;
        if(op=='H'){
            if(g)cout<<1;
            else cout<<1;
        }else{
            if(l-g)cout<<1;
            else cout<<0;
        }
    }



}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 0
Wrong Answer
time: 6ms
memory: 8504kb

input:

920 900
HHHHHHHHHHHHHHHHHHHHHHHHHGHHHHHHHHHHHHGHHHHHHHHHHHHHHHHHHHHHHHGHHGHHHHHHHGGHGHHHGHHGHGHHHHHH...

output:

1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

wrong answer 1st lines differ - expected: '001010011110011110101000100001...101010011101001110111011...

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 8512kb

input:

927 949
HHHHGHGGGHHHHGHGHHHHHGHGGHGGGHHHGGHHHHHHGGGGGGHHHGGHHHHGHHHHGGGHHHGHGHHHHGGGGHHGHHGGHGHGGGGG...

output:

1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

wrong answer 1st lines differ - expected: '111100001111011110110110011011...001100101101011111101111...

Test #3:

score: 0
Wrong Answer
time: 0ms
memory: 8512kb

input:

934 998
HHHHGHHHGHHGGGHGGHGHGHHHGHHGHGGGHHHHHGHHGGHHHHHHGHHHGGHHHHHGGHHHGHHHHHHHGHHGHGHGGHHGHGHHHGGH...

output:

1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

wrong answer 1st lines differ - expected: '110101011111101011010101111111...101110111001110010111110...

Test #4:

score: 0
Wrong Answer
time: 0ms
memory: 8512kb

input:

941 947
HHHHHHHHHHHHHHHGHHHGHHHGHHHHGHHHGHHHHHHHHGHHHHHHHHHGHHHHHGHHHHHGHHGHHHHGHGGHHGHHHHHHHHHHGGHH...

output:

1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

wrong answer 1st lines differ - expected: '111111101101011000110101010111...010110001111011001100000...

Test #5:

score: 0
Wrong Answer
time: 178ms
memory: 29116kb

input:

92189 98896
HHHHHHHHHGHHHHGGGHGHHHHHHGHHHHHGHHHHHHHHHGHGHHHGHHHHHHGGHHHGHGGHHHHHHHHHGHHHHHHGHGHGHHHG...

output:

1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

wrong answer 1st lines differ - expected: '111011111111111111111111111111...111111111111111111111111...

Test #6:

score: 0
Wrong Answer
time: 182ms
memory: 29932kb

input:

95803 95747
HHHHHHHHHHHHHGHHHHHHHHHHHHHHHHHHGHHGHGHHHHGHGHHHHHHGGHHHHHHHHHHHHGHHHGHHHHHHHHHGHGGHHHHH...

output:

1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

wrong answer 1st lines differ - expected: '101101110111111111111111110111...111110110111111011111111...

Test #7:

score: 0
Wrong Answer
time: 205ms
memory: 29220kb

input:

92610 90996
HHGGGHHGHGGGHGHGHGGGGGGHGGGHGGHGHGHGGHHHHHGHGGHGHGGGGHGGGHGGHHGHHHGGHGHGGHGGGHGGGGGGGGGG...

output:

1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

wrong answer 1st lines differ - expected: '111111111111111111101111111111...111111001111111111111111...

Test #8:

score: 0
Wrong Answer
time: 217ms
memory: 30032kb

input:

96224 91494
HHHHHHHHGGHHGHHHHHHHHHHHHHGHHHGHHHHHHHHHHHHHHHHHGGHHHHHHGHHHHHHHHHHHHHHHHHGHGGGHGHGHHHHH...

output:

1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

wrong answer 1st lines differ - expected: '111101011011110011111111111101...110101101111111111111110...

Test #9:

score: 0
Wrong Answer
time: 215ms
memory: 29308kb

input:

93031 96743
HHHHHHHHHGHHHHHHHHHHHHHHHHHGGHHHHGHHHGHHHHHHHHHGHHHHHHHHHHHHHHGGHHHHHGGHGHHHGHHHGHHHHHHG...

output:

1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

wrong answer 1st lines differ - expected: '010001111110111101111111011100...111111110111001111110101...

Test #10:

score: 0
Wrong Answer
time: 169ms
memory: 30128kb

input:

96645 93594
HHHHHHHHHGHGHHHHHHHGHHHHGGGHHHHHHHHHHHHHHHHHHGHHHHHGHGHHHHHGHGHHHHHGHHHHGHHHHGGHHGHHHHGH...

output:

1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

wrong answer 1st lines differ - expected: '010100011011111001111111111111...111001111111111111011001...