結果
問題 | No.2822 Lights Up! (Tree Edition) |
ユーザー | 🦠みどりむし |
提出日時 | 2024-06-18 19:43:17 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,434 bytes |
コンパイル時間 | 1,967 ms |
コンパイル使用メモリ | 152,016 KB |
実行使用メモリ | 23,572 KB |
最終ジャッジ日時 | 2024-06-18 19:46:57 |
合計ジャッジ時間 | 7,329 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 189 ms
23,444 KB |
testcase_02 | WA | - |
testcase_03 | AC | 161 ms
23,568 KB |
testcase_04 | AC | 190 ms
23,528 KB |
testcase_05 | AC | 136 ms
23,564 KB |
testcase_06 | AC | 138 ms
23,568 KB |
testcase_07 | AC | 82 ms
9,216 KB |
testcase_08 | AC | 137 ms
22,400 KB |
testcase_09 | WA | - |
testcase_10 | AC | 71 ms
14,808 KB |
testcase_11 | AC | 89 ms
10,752 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 5 ms
6,940 KB |
testcase_17 | AC | 12 ms
6,944 KB |
testcase_18 | AC | 6 ms
6,944 KB |
testcase_19 | AC | 7 ms
6,940 KB |
testcase_20 | WA | - |
testcase_21 | AC | 10 ms
6,940 KB |
testcase_22 | AC | 11 ms
6,944 KB |
testcase_23 | AC | 7 ms
6,940 KB |
testcase_24 | WA | - |
testcase_25 | AC | 11 ms
6,944 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 6 ms
6,944 KB |
testcase_31 | AC | 14 ms
6,940 KB |
testcase_32 | AC | 15 ms
6,944 KB |
testcase_33 | WA | - |
testcase_34 | AC | 14 ms
6,940 KB |
testcase_35 | WA | - |
testcase_36 | AC | 13 ms
6,940 KB |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | AC | 15 ms
6,940 KB |
testcase_40 | AC | 14 ms
6,940 KB |
testcase_41 | AC | 13 ms
6,944 KB |
testcase_42 | AC | 16 ms
6,940 KB |
testcase_43 | AC | 14 ms
6,944 KB |
testcase_44 | AC | 16 ms
6,944 KB |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | AC | 3 ms
6,944 KB |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | AC | 3 ms
6,940 KB |
testcase_51 | AC | 3 ms
6,944 KB |
testcase_52 | WA | - |
testcase_53 | AC | 3 ms
6,944 KB |
testcase_54 | WA | - |
testcase_55 | AC | 3 ms
6,944 KB |
testcase_56 | WA | - |
testcase_57 | AC | 3 ms
6,944 KB |
testcase_58 | AC | 3 ms
6,940 KB |
testcase_59 | AC | 3 ms
6,944 KB |
testcase_60 | WA | - |
testcase_61 | WA | - |
testcase_62 | AC | 3 ms
6,944 KB |
testcase_63 | AC | 3 ms
6,944 KB |
testcase_64 | AC | 3 ms
6,940 KB |
testcase_65 | WA | - |
testcase_66 | WA | - |
testcase_67 | WA | - |
testcase_68 | AC | 3 ms
6,944 KB |
testcase_69 | WA | - |
testcase_70 | AC | 3 ms
6,944 KB |
testcase_71 | AC | 3 ms
6,944 KB |
testcase_72 | WA | - |
testcase_73 | AC | 3 ms
6,940 KB |
testcase_74 | WA | - |
testcase_75 | WA | - |
testcase_76 | AC | 3 ms
6,944 KB |
testcase_77 | WA | - |
testcase_78 | AC | 3 ms
6,944 KB |
testcase_79 | WA | - |
testcase_80 | WA | - |
testcase_81 | WA | - |
testcase_82 | WA | - |
testcase_83 | WA | - |
testcase_84 | AC | 2 ms
6,944 KB |
testcase_85 | WA | - |
testcase_86 | WA | - |
testcase_87 | AC | 2 ms
6,944 KB |
testcase_88 | AC | 2 ms
6,944 KB |
testcase_89 | WA | - |
testcase_90 | WA | - |
testcase_91 | AC | 2 ms
6,944 KB |
testcase_92 | WA | - |
testcase_93 | WA | - |
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 | WA | - |
testcase_98 | AC | 2 ms
6,944 KB |
testcase_99 | WA | - |
testcase_100 | AC | 2 ms
6,940 KB |
testcase_101 | WA | - |
testcase_102 | AC | 2 ms
6,940 KB |
testcase_103 | AC | 2 ms
6,940 KB |
testcase_104 | WA | - |
testcase_105 | WA | - |
testcase_106 | AC | 2 ms
6,944 KB |
testcase_107 | AC | 2 ms
6,944 KB |
testcase_108 | AC | 2 ms
6,940 KB |
testcase_109 | WA | - |
testcase_110 | AC | 2 ms
6,940 KB |
testcase_111 | AC | 2 ms
6,944 KB |
testcase_112 | WA | - |
testcase_113 | AC | 2 ms
6,944 KB |
testcase_114 | WA | - |
testcase_115 | AC | 2 ms
6,944 KB |
testcase_116 | AC | 3 ms
6,944 KB |
testcase_117 | WA | - |
testcase_118 | AC | 2 ms
6,944 KB |
testcase_119 | WA | - |
testcase_120 | AC | 2 ms
6,940 KB |
testcase_121 | WA | - |
testcase_122 | AC | 3 ms
6,944 KB |
testcase_123 | WA | - |
testcase_124 | AC | 3 ms
6,944 KB |
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,940 KB |
testcase_129 | WA | - |
testcase_130 | WA | - |
testcase_131 | AC | 3 ms
6,944 KB |
testcase_132 | WA | - |
testcase_133 | WA | - |
testcase_134 | WA | - |
testcase_135 | WA | - |
testcase_136 | WA | - |
testcase_137 | AC | 2 ms
6,940 KB |
testcase_138 | AC | 3 ms
6,940 KB |
testcase_139 | AC | 3 ms
6,944 KB |
testcase_140 | AC | 3 ms
6,940 KB |
testcase_141 | AC | 3 ms
6,940 KB |
testcase_142 | WA | - |
ソースコード
#include <iostream> #include <ranges> #include <valarray> #include <string> #include <atcoder/dsu> struct Edge { long long to; }; using Graph = std::vector<std::vector<Edge>>; struct LCA { std::vector<std::vector<int>> parent; std::vector<int> dist; LCA(const Graph &G, int root = 0) { init(G, root); } void init(const Graph &G, int root = 0) { int V = G.size(); int K = 1; while ((1 << K) < V) K++; parent.assign(K, std::vector<int>(V, -1)); dist.assign(V, -1); dfs(G, root, -1, 0); for (int k = 0; k + 1 < K; k++) { for (int v = 0; v < V; v++) { if (parent[k][v] < 0) { parent[k + 1][v] = -1; } else { parent[k + 1][v] = parent[k][parent[k][v]]; } } } } void dfs(const Graph &G, int v, int p, int d) { parent[0][v] = p; dist[v] = d; for (auto e : G[v]) { if (e.to != p) dfs(G, e.to, v, d + 1); } } int query(int u, int v) { if (dist[u] < dist[v]) std::swap(u, v); int K = parent.size(); for (int k = 0; k < K; k++) { if ((dist[u] - dist[v]) >> k & 1) { u = parent[k][u]; } } if (u == v) return u; for (int k = K - 1; k >= 0; k--) { if (parent[k][u] != parent[k][v]) { u = parent[k][u]; v = parent[k][v]; } } return parent[0][u]; } }; signed main() { int n; std::cin >> n; std::valarray<int> p(n); Graph tree(n); for(auto i : std::views::iota(1, n)) { std::cin >> p[i], --p[i]; tree[p[i]].emplace_back(i), tree[i].emplace_back(p[i]); } LCA lca(tree, n - 1); std::valarray<bool> v(n); std::string s; std::cin >> s; for(const auto i : std::views::iota(1, n)) v[i] = s[i - 1] == '#'; atcoder::dsu ds(n); int q; std::cin >> q; for(const auto _ : std::views::iota(0, q)) { int x, y; std::cin >> x >> y; --x, --y; ds.merge(x, lca.query(x, y)); ds.merge(x, lca.query(x, y)); } for(const auto i : std::views::iota(1, n)) { v[p[i]] ^= s[i - 1] == '#'; } for(const auto& group : ds.groups()) { bool x = false; for(const auto i : group) x ^= v[i]; if(x) { std::cout << "No" << "\n"; return 0; } } std::cout << "Yes" << "\n"; }