結果
問題 | No.2822 Lights Up! (Tree Edition) |
ユーザー | Astral__ |
提出日時 | 2024-07-26 23:39:18 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,133 bytes |
コンパイル時間 | 11,021 ms |
コンパイル使用メモリ | 562,508 KB |
実行使用メモリ | 25,396 KB |
最終ジャッジ日時 | 2024-07-26 23:39:42 |
合計ジャッジ時間 | 20,703 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 578 ms
25,008 KB |
testcase_03 | WA | - |
testcase_04 | AC | 461 ms
25,108 KB |
testcase_05 | AC | 559 ms
24,952 KB |
testcase_06 | AC | 243 ms
25,396 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 388 ms
23,400 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 345 ms
17,448 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 9 ms
6,940 KB |
testcase_18 | WA | - |
testcase_19 | AC | 6 ms
6,944 KB |
testcase_20 | AC | 20 ms
6,944 KB |
testcase_21 | WA | - |
testcase_22 | AC | 10 ms
6,940 KB |
testcase_23 | AC | 27 ms
6,940 KB |
testcase_24 | AC | 6 ms
6,940 KB |
testcase_25 | AC | 4 ms
6,940 KB |
testcase_26 | AC | 19 ms
6,944 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 17 ms
6,940 KB |
testcase_32 | AC | 33 ms
6,940 KB |
testcase_33 | AC | 35 ms
6,940 KB |
testcase_34 | WA | - |
testcase_35 | AC | 35 ms
6,940 KB |
testcase_36 | WA | - |
testcase_37 | AC | 27 ms
6,940 KB |
testcase_38 | WA | - |
testcase_39 | AC | 13 ms
6,940 KB |
testcase_40 | WA | - |
testcase_41 | AC | 30 ms
6,944 KB |
testcase_42 | AC | 13 ms
6,940 KB |
testcase_43 | AC | 33 ms
6,940 KB |
testcase_44 | AC | 30 ms
6,940 KB |
testcase_45 | AC | 30 ms
6,940 KB |
testcase_46 | AC | 34 ms
6,940 KB |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | AC | 4 ms
6,940 KB |
testcase_52 | AC | 4 ms
6,940 KB |
testcase_53 | WA | - |
testcase_54 | AC | 4 ms
6,940 KB |
testcase_55 | WA | - |
testcase_56 | AC | 4 ms
6,940 KB |
testcase_57 | AC | 3 ms
6,940 KB |
testcase_58 | AC | 4 ms
6,944 KB |
testcase_59 | AC | 4 ms
6,940 KB |
testcase_60 | AC | 5 ms
6,940 KB |
testcase_61 | WA | - |
testcase_62 | WA | - |
testcase_63 | AC | 4 ms
6,940 KB |
testcase_64 | AC | 4 ms
6,940 KB |
testcase_65 | AC | 4 ms
6,944 KB |
testcase_66 | WA | - |
testcase_67 | WA | - |
testcase_68 | WA | - |
testcase_69 | WA | - |
testcase_70 | WA | - |
testcase_71 | AC | 3 ms
6,944 KB |
testcase_72 | WA | - |
testcase_73 | AC | 3 ms
6,940 KB |
testcase_74 | AC | 5 ms
6,940 KB |
testcase_75 | AC | 3 ms
6,940 KB |
testcase_76 | WA | - |
testcase_77 | WA | - |
testcase_78 | WA | - |
testcase_79 | AC | 3 ms
6,940 KB |
testcase_80 | AC | 2 ms
6,940 KB |
testcase_81 | WA | - |
testcase_82 | AC | 2 ms
6,940 KB |
testcase_83 | AC | 3 ms
6,940 KB |
testcase_84 | AC | 2 ms
6,940 KB |
testcase_85 | AC | 2 ms
6,940 KB |
testcase_86 | WA | - |
testcase_87 | WA | - |
testcase_88 | AC | 2 ms
6,940 KB |
testcase_89 | AC | 2 ms
6,940 KB |
testcase_90 | AC | 2 ms
6,940 KB |
testcase_91 | WA | - |
testcase_92 | AC | 2 ms
6,940 KB |
testcase_93 | WA | - |
testcase_94 | WA | - |
testcase_95 | AC | 2 ms
6,944 KB |
testcase_96 | AC | 2 ms
6,944 KB |
testcase_97 | AC | 2 ms
6,944 KB |
testcase_98 | WA | - |
testcase_99 | AC | 2 ms
6,940 KB |
testcase_100 | WA | - |
testcase_101 | WA | - |
testcase_102 | WA | - |
testcase_103 | AC | 2 ms
6,940 KB |
testcase_104 | AC | 2 ms
6,944 KB |
testcase_105 | WA | - |
testcase_106 | WA | - |
testcase_107 | AC | 2 ms
6,940 KB |
testcase_108 | WA | - |
testcase_109 | WA | - |
testcase_110 | WA | - |
testcase_111 | WA | - |
testcase_112 | AC | 2 ms
6,944 KB |
testcase_113 | AC | 4 ms
6,940 KB |
testcase_114 | WA | - |
testcase_115 | WA | - |
testcase_116 | AC | 3 ms
6,940 KB |
testcase_117 | AC | 4 ms
6,940 KB |
testcase_118 | WA | - |
testcase_119 | AC | 3 ms
6,940 KB |
testcase_120 | WA | - |
testcase_121 | WA | - |
testcase_122 | WA | - |
testcase_123 | AC | 4 ms
6,944 KB |
testcase_124 | WA | - |
testcase_125 | WA | - |
testcase_126 | AC | 3 ms
6,944 KB |
testcase_127 | WA | - |
testcase_128 | AC | 5 ms
6,944 KB |
testcase_129 | WA | - |
testcase_130 | WA | - |
testcase_131 | WA | - |
testcase_132 | WA | - |
testcase_133 | AC | 4 ms
6,940 KB |
testcase_134 | AC | 4 ms
6,940 KB |
testcase_135 | WA | - |
testcase_136 | AC | 4 ms
6,940 KB |
testcase_137 | WA | - |
testcase_138 | AC | 4 ms
6,940 KB |
testcase_139 | AC | 4 ms
6,944 KB |
testcase_140 | AC | 4 ms
6,944 KB |
testcase_141 | AC | 4 ms
6,940 KB |
testcase_142 | AC | 4 ms
6,944 KB |
testcase_143 | WA | - |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> #include <boost/multiprecision/cpp_dec_float.hpp> #include <boost/multiprecision/cpp_int.hpp> #include <boost/rational.hpp> // 任意長整数型 using Bint = boost::multiprecision::cpp_int; // 仮数部が10進数で1024桁の浮動小数点数型(TLEしたら小さくする) using Real = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1024>>; using Rat = boost::rational<Bint>; using namespace std; using ll = long long; using pll = pair<ll, ll>; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define rrep(i, s, t) for (ll i = (ll)(t) - 1; i >= (ll)(s); i--) #define all(x) begin(x), end(x) #define TT template <typename T> TT using vec = vector<T>; TT using vvec = vec<vec<T>>; TT using vvvec = vec<vvec<T>>; TT using minheap = priority_queue<T, vector<T>, greater<T>>; TT using maxheap = priority_queue<T>; template <class T1, class T2> bool chmin(T1 &x, T2 y) { return x > y ? (x = y, true) : false; } template <class T1, class T2> bool chmax(T1 &x, T2 y) { return x < y ? (x = y, true) : false; } TT auto prev_itr(vec<T> &A, T x) { // must sorted auto res = lower_bound(all(A), x); if (res == A.begin()) return A.end(); else return --res; } TT auto next_itr(vec<T> &A, T x) { // must sorted return upper_bound(all(A), x) - A.begin(); } struct io_setup { io_setup() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(15); } } io_setup; int main() { ll n; cin >> n; vec<vec<int>> g(n); rep(i, 1, n) { int p; cin >> p; p--; g[i].push_back(p); g[p].push_back(i); } vec<int> col(n, 0); rep(i, 1, n) { char c; cin >> c; if (c == '#') col[i] = 1; //変える必要がある。 } ll k; cin >> k; vec<int> U(k), V(k); rep(i, 0, k) { cin >> U[i] >> V[i]; U[i]--, V[i]--; } vec<set<int>> rev(n); rep(i, 0, k) { rev[U[i]].insert(i); rev[V[i]].insert(i); } vec<int> base(n, -1); auto path_xor = [&](int id1, int id2) { // id2を変更する。 int v = -1; map<int, int> cnt; cnt[U[id1]]++; cnt[V[id1]]++; cnt[U[id2]]++; cnt[V[id2]]++; for(auto [num, c] : cnt) if(c == 2) v = num; int nl, nr; if (U[id1] == v) nl = V[id1]; else nl = U[id1]; if (U[id2] == v) nr = V[id2]; else nr = U[id2]; rev[U[id2]].erase(id2); rev[V[id2]].erase(id2); U[id2] = nl; V[id2] = nr; if (nl == nr) return; rev[U[id2]].insert(id2); rev[V[id2]].insert(id2); return; }; auto dfs = [&](auto f, int v, int p = -1) -> void { for(int to : g[v]) if(to != p) { f(f, to, v); } if(rev[v].empty()) return; int use = *begin(rev[v]); vec<int> tar; for(int id : rev[U[use]]) if(id != use) tar.push_back(id); for(int id : rev[V[use]]) if(id != use) tar.push_back(id); sort(all(tar)); tar.erase(unique(all(tar)), tar.end()); for(int id : tar) path_xor(use, id); /* vec<int> era; for(int di : rev[v]) era.push_back(di); for(int di : era) path_xor(v, use, di); */ base[v] = use; rev[U[use]].erase(use); rev[V[use]].erase(use); return; }; dfs(dfs, 0); vec<int> imos(n, 0); rep(i, 0, n) if(base[i] != -1 && col[i] == 1) { int id = base[i]; imos[U[id]]++; imos[V[id]]++; } auto dfs2 = [&](auto f, int v, int p = -1) -> bool { for(int to : g[v]) if(to != p) { if(f(f, to, v) == false) { return false; } } if(p != -1) imos[p] += imos[v]; if((imos[v] % 2) != col[v]) { return false; } else return true; }; if(dfs2(dfs2, 0)) cout << "Yes" << endl; else cout << "No" << endl; }