結果
問題 | No.2822 Lights Up! (Tree Edition) |
ユーザー | FplusFplusF |
提出日時 | 2024-06-15 05:45:53 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,600 bytes |
コンパイル時間 | 3,084 ms |
コンパイル使用メモリ | 266,232 KB |
実行使用メモリ | 30,212 KB |
最終ジャッジ日時 | 2024-06-18 19:46:02 |
合計ジャッジ時間 | 7,355 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 103 ms
29,708 KB |
testcase_02 | AC | 75 ms
25,884 KB |
testcase_03 | AC | 71 ms
25,860 KB |
testcase_04 | AC | 110 ms
30,212 KB |
testcase_05 | AC | 65 ms
25,716 KB |
testcase_06 | AC | 70 ms
25,852 KB |
testcase_07 | AC | 35 ms
11,116 KB |
testcase_08 | AC | 64 ms
24,372 KB |
testcase_09 | WA | - |
testcase_10 | AC | 39 ms
16,288 KB |
testcase_11 | AC | 38 ms
12,648 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 41 ms
14,892 KB |
testcase_15 | AC | 3 ms
6,944 KB |
testcase_16 | AC | 4 ms
6,944 KB |
testcase_17 | AC | 7 ms
6,944 KB |
testcase_18 | AC | 5 ms
6,944 KB |
testcase_19 | AC | 5 ms
6,944 KB |
testcase_20 | WA | - |
testcase_21 | AC | 6 ms
6,944 KB |
testcase_22 | AC | 8 ms
6,944 KB |
testcase_23 | AC | 5 ms
6,940 KB |
testcase_24 | AC | 3 ms
6,940 KB |
testcase_25 | AC | 7 ms
6,944 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 4 ms
6,940 KB |
testcase_31 | AC | 7 ms
6,940 KB |
testcase_32 | AC | 8 ms
6,940 KB |
testcase_33 | AC | 8 ms
6,944 KB |
testcase_34 | AC | 8 ms
6,940 KB |
testcase_35 | WA | - |
testcase_36 | AC | 7 ms
6,940 KB |
testcase_37 | AC | 8 ms
6,940 KB |
testcase_38 | AC | 8 ms
6,944 KB |
testcase_39 | AC | 8 ms
6,940 KB |
testcase_40 | AC | 7 ms
6,944 KB |
testcase_41 | AC | 9 ms
6,944 KB |
testcase_42 | AC | 10 ms
6,940 KB |
testcase_43 | AC | 8 ms
6,940 KB |
testcase_44 | AC | 10 ms
6,944 KB |
testcase_45 | AC | 8 ms
6,944 KB |
testcase_46 | WA | - |
testcase_47 | AC | 3 ms
6,940 KB |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | AC | 2 ms
6,940 KB |
testcase_51 | AC | 2 ms
6,944 KB |
testcase_52 | AC | 2 ms
6,944 KB |
testcase_53 | AC | 2 ms
6,940 KB |
testcase_54 | AC | 3 ms
6,940 KB |
testcase_55 | AC | 2 ms
6,944 KB |
testcase_56 | AC | 2 ms
6,940 KB |
testcase_57 | AC | 2 ms
6,940 KB |
testcase_58 | AC | 2 ms
6,940 KB |
testcase_59 | AC | 2 ms
6,944 KB |
testcase_60 | WA | - |
testcase_61 | AC | 3 ms
6,944 KB |
testcase_62 | AC | 2 ms
6,940 KB |
testcase_63 | AC | 2 ms
6,940 KB |
testcase_64 | AC | 3 ms
6,940 KB |
testcase_65 | WA | - |
testcase_66 | AC | 2 ms
6,940 KB |
testcase_67 | WA | - |
testcase_68 | AC | 2 ms
6,944 KB |
testcase_69 | WA | - |
testcase_70 | AC | 2 ms
6,940 KB |
testcase_71 | AC | 2 ms
6,944 KB |
testcase_72 | AC | 2 ms
6,940 KB |
testcase_73 | AC | 3 ms
6,940 KB |
testcase_74 | AC | 2 ms
6,944 KB |
testcase_75 | WA | - |
testcase_76 | AC | 2 ms
6,940 KB |
testcase_77 | WA | - |
testcase_78 | AC | 2 ms
6,944 KB |
testcase_79 | AC | 2 ms
6,944 KB |
testcase_80 | WA | - |
testcase_81 | AC | 2 ms
6,940 KB |
testcase_82 | AC | 2 ms
6,944 KB |
testcase_83 | AC | 2 ms
6,940 KB |
testcase_84 | AC | 2 ms
6,944 KB |
testcase_85 | AC | 2 ms
6,944 KB |
testcase_86 | WA | - |
testcase_87 | AC | 2 ms
6,940 KB |
testcase_88 | AC | 2 ms
6,940 KB |
testcase_89 | AC | 2 ms
6,940 KB |
testcase_90 | WA | - |
testcase_91 | AC | 2 ms
6,940 KB |
testcase_92 | WA | - |
testcase_93 | AC | 2 ms
6,940 KB |
testcase_94 | AC | 2 ms
6,944 KB |
testcase_95 | AC | 2 ms
6,940 KB |
testcase_96 | AC | 2 ms
6,940 KB |
testcase_97 | AC | 2 ms
6,940 KB |
testcase_98 | AC | 2 ms
6,944 KB |
testcase_99 | WA | - |
testcase_100 | AC | 2 ms
6,944 KB |
testcase_101 | AC | 2 ms
6,940 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,944 KB |
testcase_106 | AC | 2 ms
6,944 KB |
testcase_107 | AC | 2 ms
6,944 KB |
testcase_108 | WA | - |
testcase_109 | WA | - |
testcase_110 | AC | 1 ms
6,940 KB |
testcase_111 | AC | 2 ms
6,944 KB |
testcase_112 | AC | 2 ms
6,944 KB |
testcase_113 | WA | - |
testcase_114 | WA | - |
testcase_115 | AC | 2 ms
6,940 KB |
testcase_116 | AC | 2 ms
6,944 KB |
testcase_117 | WA | - |
testcase_118 | AC | 2 ms
6,940 KB |
testcase_119 | WA | - |
testcase_120 | AC | 2 ms
6,940 KB |
testcase_121 | AC | 3 ms
6,944 KB |
testcase_122 | AC | 2 ms
6,940 KB |
testcase_123 | AC | 2 ms
6,940 KB |
testcase_124 | WA | - |
testcase_125 | AC | 2 ms
6,944 KB |
testcase_126 | WA | - |
testcase_127 | AC | 2 ms
6,944 KB |
testcase_128 | AC | 2 ms
6,944 KB |
testcase_129 | WA | - |
testcase_130 | WA | - |
testcase_131 | AC | 2 ms
6,940 KB |
testcase_132 | AC | 2 ms
6,944 KB |
testcase_133 | AC | 2 ms
6,944 KB |
testcase_134 | WA | - |
testcase_135 | AC | 2 ms
6,944 KB |
testcase_136 | AC | 2 ms
6,940 KB |
testcase_137 | AC | 2 ms
6,940 KB |
testcase_138 | AC | 2 ms
6,944 KB |
testcase_139 | AC | 2 ms
6,940 KB |
testcase_140 | AC | 2 ms
6,940 KB |
testcase_141 | AC | 2 ms
6,940 KB |
testcase_142 | WA | - |
ソースコード
#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){ ll x=in[ord[i]],y=out[ord[i]]; if(i==x) x=y; if(!((BIT.get(i)+BIT.get(x))&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){ ll x=in[ord[i]],y=out[ord[i]]; if(i==x) x=y; if((BIT.get(i)+BIT.get(x))&1){ cout << "No\n"; return 0; } } cout << "Yes\n"; }