結果

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

テストケース

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

ソースコード

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;
    }
};
vector<vector<ll>> g;
vector<ll> ord,in,out;
void dfs(ll x,ll p){
    in[x]=len(ord);
    ord.push_back(x);
    for(auto i:g[x]){
        if(i==p) continue;
        dfs(i,x);
    }
    out[x]=len(ord);
    ord.push_back(x);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    g.resize(n);
    in.resize(n);
    out.resize(n);
    vector<ll> p(n,-1);
    replr(i,1,n){
        cin >> p[i];
        p[i]--;
        g[i].push_back(p[i]);
        g[p[i]].push_back(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]--;
    }

    dfs(0,-1);
    
    ll sz=len(ord);
    vector<set<ll>> lr(sz);
    rep(i,q){
        if(out[u[i]]>out[v[i]]) swap(u[i],v[i]);
        u[i]=out[u[i]];
        v[i]=out[v[i]];
        lr[u[i]].insert(v[i]);
    }
    
    fenwick_tree<ll> BIT(sz);
    replr(i,1,n){
        if(s[i]=='#') BIT.add(out[i],out[i]+1,1);
    }

    rep(i,sz){
        if(!(BIT.get(i)&1)) continue;
        if(lr[i].empty()) continue;
        ll j=*begin(lr[i]);
        BIT.add(i,j,1);
        lr[i].erase(j);
        if(len(lr[i])<len(lr[j])){
            for(auto k:lr[i]) lr[j].insert(k);
        }else{
            for(auto k:lr[j]) lr[i].insert(k);
            swap(lr[i],lr[j]);
        }
        lr[i].clear();
    }
    

    rep(i,sz){
        if(BIT.get(i)&1&&out[ord[i]]==i){
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
}
0