結果

問題 No.2822 Lights Up! (Tree Edition)
ユーザー FplusFplusFFplusFplusF
提出日時 2024-06-15 09:05:31
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,211 bytes
コンパイル時間 3,718 ms
コンパイル使用メモリ 264,232 KB
実行使用メモリ 14,080 KB
最終ジャッジ日時 2024-06-18 19:46:36
合計ジャッジ時間 7,846 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 WA -
testcase_02 AC 99 ms
13,952 KB
testcase_03 AC 95 ms
13,824 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 88 ms
13,952 KB
testcase_07 AC 56 ms
7,424 KB
testcase_08 WA -
testcase_09 AC 82 ms
10,240 KB
testcase_10 AC 44 ms
9,344 KB
testcase_11 WA -
testcase_12 AC 49 ms
6,940 KB
testcase_13 AC 57 ms
8,960 KB
testcase_14 AC 61 ms
9,088 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 WA -
testcase_17 AC 8 ms
6,944 KB
testcase_18 AC 4 ms
6,940 KB
testcase_19 AC 5 ms
6,944 KB
testcase_20 AC 8 ms
6,944 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 4 ms
6,940 KB
testcase_24 AC 3 ms
6,944 KB
testcase_25 AC 6 ms
6,940 KB
testcase_26 AC 3 ms
6,940 KB
testcase_27 AC 6 ms
6,940 KB
testcase_28 AC 10 ms
6,948 KB
testcase_29 AC 7 ms
6,940 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 9 ms
6,948 KB
testcase_34 WA -
testcase_35 AC 10 ms
6,940 KB
testcase_36 WA -
testcase_37 AC 8 ms
6,948 KB
testcase_38 AC 8 ms
6,940 KB
testcase_39 AC 10 ms
6,944 KB
testcase_40 WA -
testcase_41 AC 8 ms
6,944 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 11 ms
6,944 KB
testcase_47 AC 3 ms
6,944 KB
testcase_48 AC 3 ms
6,944 KB
testcase_49 AC 2 ms
6,940 KB
testcase_50 WA -
testcase_51 WA -
testcase_52 AC 2 ms
6,940 KB
testcase_53 WA -
testcase_54 AC 2 ms
6,940 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 AC 2 ms
6,944 KB
testcase_59 AC 2 ms
6,940 KB
testcase_60 AC 3 ms
6,940 KB
testcase_61 AC 3 ms
6,940 KB
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 AC 2 ms
6,944 KB
testcase_66 AC 2 ms
6,944 KB
testcase_67 AC 2 ms
6,944 KB
testcase_68 AC 2 ms
6,940 KB
testcase_69 AC 3 ms
6,940 KB
testcase_70 AC 2 ms
6,940 KB
testcase_71 AC 3 ms
6,940 KB
testcase_72 AC 2 ms
6,944 KB
testcase_73 WA -
testcase_74 WA -
testcase_75 AC 2 ms
6,940 KB
testcase_76 AC 3 ms
6,940 KB
testcase_77 AC 3 ms
6,940 KB
testcase_78 WA -
testcase_79 AC 2 ms
6,940 KB
testcase_80 AC 2 ms
6,944 KB
testcase_81 WA -
testcase_82 AC 2 ms
6,944 KB
testcase_83 WA -
testcase_84 AC 2 ms
6,940 KB
testcase_85 AC 2 ms
6,944 KB
testcase_86 AC 2 ms
6,940 KB
testcase_87 AC 2 ms
6,944 KB
testcase_88 AC 2 ms
6,944 KB
testcase_89 AC 2 ms
6,944 KB
testcase_90 AC 2 ms
6,940 KB
testcase_91 AC 2 ms
6,940 KB
testcase_92 AC 1 ms
6,944 KB
testcase_93 AC 1 ms
6,940 KB
testcase_94 AC 2 ms
6,940 KB
testcase_95 AC 2 ms
6,944 KB
testcase_96 WA -
testcase_97 AC 2 ms
6,940 KB
testcase_98 AC 2 ms
6,944 KB
testcase_99 AC 2 ms
6,940 KB
testcase_100 AC 2 ms
6,940 KB
testcase_101 AC 2 ms
6,944 KB
testcase_102 AC 2 ms
6,940 KB
testcase_103 AC 2 ms
6,944 KB
testcase_104 AC 2 ms
6,940 KB
testcase_105 AC 2 ms
6,940 KB
testcase_106 AC 2 ms
6,940 KB
testcase_107 AC 2 ms
6,940 KB
testcase_108 AC 2 ms
6,944 KB
testcase_109 AC 2 ms
6,944 KB
testcase_110 AC 2 ms
6,940 KB
testcase_111 WA -
testcase_112 WA -
testcase_113 AC 2 ms
6,940 KB
testcase_114 AC 2 ms
6,944 KB
testcase_115 WA -
testcase_116 WA -
testcase_117 AC 2 ms
6,944 KB
testcase_118 WA -
testcase_119 AC 3 ms
6,944 KB
testcase_120 AC 2 ms
6,940 KB
testcase_121 AC 2 ms
6,940 KB
testcase_122 WA -
testcase_123 AC 2 ms
6,940 KB
testcase_124 AC 2 ms
6,940 KB
testcase_125 WA -
testcase_126 AC 2 ms
6,944 KB
testcase_127 WA -
testcase_128 AC 2 ms
6,940 KB
testcase_129 AC 2 ms
6,940 KB
testcase_130 AC 2 ms
6,940 KB
testcase_131 AC 2 ms
6,944 KB
testcase_132 WA -
testcase_133 WA -
testcase_134 AC 3 ms
6,940 KB
testcase_135 WA -
testcase_136 AC 2 ms
6,944 KB
testcase_137 WA -
testcase_138 WA -
testcase_139 WA -
testcase_140 AC 2 ms
6,944 KB
testcase_141 AC 2 ms
6,944 KB
testcase_142 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
using ld=long double;
const ll INF=(1ll<<60);
#define rep(i,n) for (ll i=0;i<(ll)(n);i++)
#define replr(i,l,r) for (ll i=(ll)(l);i<(ll)(r);i++)
#define all(v) v.begin(),v.end()
#define len(v) ((ll)v.size())
template<class T> inline bool chmin(T &a,T b){
    if(a>b){
        a=b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T &a,T b){
    if(a<b){
        a=b;
        return true;
    }
    return false;
}
template<class T> struct fenwick_tree{
    vector<T> v;
    int n;
    fenwick_tree(int x){
        n=x+1;
        v.assign(n+1,0);
    }
    fenwick_tree(vector<T> &a){
        n=(int)a.size()+1;
        v.assign(n+1,0);
        if((int)a.size()==0) return;
        v[1]=a[0];
        for(int i=0;i<n-2;i++) v[i+2]=a[i+1]-a[i];
        for(int idx=1;idx<=n;idx++){
            if(n<idx+(idx&(-idx))) continue;
            v[idx+(idx&(-idx))]+=v[idx];
        }
    }
    void add_sub(int i,T x){
        i++;
        for(int idx=i;idx<=n;idx+=(idx&(-idx))){
            v[idx]+=x;
        }
    }
    void add(int l,int r,T x){  //[l,r)
        assert(0<=l&&l<=n);
        assert(0<=r&&r<=n);
        assert(l<=r);
        add_sub(l,x);
        add_sub(r,-x);
    }
    T get(int i){
        assert(0<=i&&i<n);
        i++;
        T ret=0;
        for(int idx=i;0<idx;idx-=(idx&(-idx))){
            ret+=v[idx];
        }
        return ret;
    }
    int lower_bound(T w){
        if(w<=0) return 0;
        int x=0;
        static int r=1;
        if(r==1){
            while((r<<1)<=n) r<<=1;
        }
        while((r<<1)<=n) r<<=1;
        for(int k=r;0<k;k>>=1){
            if(x+k<=n&&v[x+k]<w){
                w-=v[x+k];
                x+=k;
            }
        }
        x++;
        return x;
    }
};
struct HLD{
    int n;
    vector<vector<int>> g;
    vector<int> par,sz,in,out,head;
    int ord=0;
    HLD(int x){
        n=x;
        g.resize(n);
        par.resize(n);
        sz.assign(n,0);
        in.resize(n);
        out.resize(n);
        head.resize(n);
    }
    void add_edge(int u,int v){
        g[u].push_back(v);
        g[v].push_back(u);
    }
    void dfs_sz(int x,int p){
        sz[x]++;
        if(0<g[x].size()&&g[x].front()==p) swap(g[x].front(),g[x].back());
        for(auto &i:g[x]){
            if(i==p) continue;
            dfs_sz(i,x);
            sz[x]+=sz[i];
            if(sz[g[x].front()]<sz[i]) swap(g[x].front(),i);
        }
    }
    void dfs_hld(int x,int p){
        par[x]=p;
        in[x]=ord;
        ord++;
        for(auto &i:g[x]){
            if(i==p) continue;
            if(i==g[x].front()) head[i]=head[x];
            else head[i]=i;
            dfs_hld(i,x);
        }
        out[x]=ord;
    }
    void solve(int root){
        dfs_sz(root,-1);
        dfs_hld(root,-1);
    }
    vector<pair<int,int>> query(int u,int v,bool edge){
        vector<pair<int,int>> ret;
        while(true){
            if(in[v]<in[u]) swap(u,v);
            if(head[u]==head[v]) break;
            ret.emplace_back(in[head[v]],in[v]+1);
            v=par[head[v]];
        }
        if(in[u]+edge!=in[v]+1) ret.emplace_back(in[u]+edge,in[v]+1);
        return ret;
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    vector<ll> p(n,-1);
    HLD h(n);
    replr(i,1,n){
        cin >> p[i];
        p[i]--;
        h.add_edge(i,p[i]);
    }
    
    string s(n,'x');
    replr(i,1,n) cin >> s[i];
    ll q;
    cin >> q;
    vector<ll> u(q),v(q);
    rep(i,q){
        cin >> u[i] >> v[i];
        u[i]--;
        v[i]--;
    }

    h.solve(0);
    fenwick_tree<ll> BIT(n);

    auto update=[&](ll a,ll b){
        auto now=h.query(a,b,true);
        for(auto [l,r]:now){
            BIT.add(l,r,1);
        }
    };

    auto get=[&](ll a,ll b){
        auto now=h.query(a,b,true);
        return BIT.get(now[0].first);
    };
    rep(i,q) update(u[i],v[i]);
    replr(i,1,n){
        if(s[i]=='#'&&get(i,p[i])==0){
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
}
0