結果
問題 | No.2822 Lights Up! (Tree Edition) |
ユーザー | 🦠みどりむし |
提出日時 | 2024-06-18 19:28:44 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,448 bytes |
コンパイル時間 | 2,127 ms |
コンパイル使用メモリ | 149,472 KB |
実行使用メモリ | 23,568 KB |
最終ジャッジ日時 | 2024-06-18 19:46:51 |
合計ジャッジ時間 | 7,936 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | WA | - |
testcase_02 | AC | 169 ms
23,564 KB |
testcase_03 | AC | 171 ms
23,568 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | AC | 147 ms
23,568 KB |
testcase_07 | AC | 90 ms
9,216 KB |
testcase_08 | WA | - |
testcase_09 | AC | 157 ms
15,684 KB |
testcase_10 | AC | 79 ms
14,684 KB |
testcase_11 | WA | - |
testcase_12 | AC | 82 ms
7,040 KB |
testcase_13 | AC | 106 ms
12,768 KB |
testcase_14 | AC | 105 ms
12,888 KB |
testcase_15 | AC | 5 ms
6,940 KB |
testcase_16 | AC | 6 ms
6,940 KB |
testcase_17 | AC | 13 ms
6,940 KB |
testcase_18 | AC | 7 ms
6,944 KB |
testcase_19 | AC | 8 ms
6,940 KB |
testcase_20 | AC | 12 ms
6,940 KB |
testcase_21 | WA | - |
testcase_22 | AC | 12 ms
6,944 KB |
testcase_23 | AC | 9 ms
6,940 KB |
testcase_24 | AC | 5 ms
6,940 KB |
testcase_25 | AC | 12 ms
6,940 KB |
testcase_26 | AC | 4 ms
6,940 KB |
testcase_27 | AC | 10 ms
6,940 KB |
testcase_28 | AC | 15 ms
6,940 KB |
testcase_29 | AC | 11 ms
6,940 KB |
testcase_30 | AC | 7 ms
6,940 KB |
testcase_31 | AC | 15 ms
6,940 KB |
testcase_32 | WA | - |
testcase_33 | AC | 17 ms
6,944 KB |
testcase_34 | AC | 16 ms
6,944 KB |
testcase_35 | AC | 17 ms
6,940 KB |
testcase_36 | AC | 15 ms
6,940 KB |
testcase_37 | AC | 15 ms
6,940 KB |
testcase_38 | AC | 14 ms
6,940 KB |
testcase_39 | AC | 17 ms
6,944 KB |
testcase_40 | AC | 15 ms
6,940 KB |
testcase_41 | AC | 15 ms
6,944 KB |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | AC | 17 ms
6,940 KB |
testcase_47 | AC | 3 ms
6,944 KB |
testcase_48 | AC | 3 ms
6,944 KB |
testcase_49 | AC | 3 ms
6,944 KB |
testcase_50 | WA | - |
testcase_51 | AC | 3 ms
6,940 KB |
testcase_52 | AC | 3 ms
6,944 KB |
testcase_53 | AC | 3 ms
6,940 KB |
testcase_54 | AC | 3 ms
6,940 KB |
testcase_55 | AC | 3 ms
6,940 KB |
testcase_56 | AC | 3 ms
6,940 KB |
testcase_57 | WA | - |
testcase_58 | AC | 3 ms
6,940 KB |
testcase_59 | AC | 3 ms
6,944 KB |
testcase_60 | AC | 3 ms
6,944 KB |
testcase_61 | AC | 4 ms
6,948 KB |
testcase_62 | AC | 3 ms
6,940 KB |
testcase_63 | WA | - |
testcase_64 | WA | - |
testcase_65 | AC | 4 ms
6,940 KB |
testcase_66 | AC | 3 ms
6,940 KB |
testcase_67 | AC | 4 ms
6,940 KB |
testcase_68 | AC | 4 ms
6,940 KB |
testcase_69 | AC | 4 ms
6,944 KB |
testcase_70 | AC | 3 ms
6,940 KB |
testcase_71 | AC | 3 ms
6,944 KB |
testcase_72 | AC | 3 ms
6,940 KB |
testcase_73 | AC | 3 ms
6,940 KB |
testcase_74 | WA | - |
testcase_75 | AC | 4 ms
6,944 KB |
testcase_76 | AC | 4 ms
6,940 KB |
testcase_77 | AC | 4 ms
6,940 KB |
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 | 3 ms
6,940 KB |
testcase_83 | WA | - |
testcase_84 | AC | 2 ms
6,940 KB |
testcase_85 | AC | 3 ms
6,940 KB |
testcase_86 | AC | 2 ms
6,944 KB |
testcase_87 | AC | 2 ms
6,940 KB |
testcase_88 | AC | 3 ms
6,940 KB |
testcase_89 | AC | 2 ms
6,940 KB |
testcase_90 | AC | 2 ms
6,940 KB |
testcase_91 | AC | 2 ms
6,944 KB |
testcase_92 | AC | 2 ms
6,944 KB |
testcase_93 | AC | 2 ms
6,944 KB |
testcase_94 | AC | 2 ms
6,944 KB |
testcase_95 | AC | 2 ms
6,940 KB |
testcase_96 | AC | 3 ms
6,944 KB |
testcase_97 | AC | 3 ms
6,940 KB |
testcase_98 | AC | 2 ms
6,940 KB |
testcase_99 | AC | 2 ms
6,944 KB |
testcase_100 | AC | 2 ms
6,944 KB |
testcase_101 | AC | 2 ms
6,944 KB |
testcase_102 | AC | 2 ms
6,940 KB |
testcase_103 | AC | 2 ms
6,940 KB |
testcase_104 | AC | 2 ms
6,944 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,944 KB |
testcase_111 | WA | - |
testcase_112 | WA | - |
testcase_113 | AC | 2 ms
6,944 KB |
testcase_114 | AC | 3 ms
6,940 KB |
testcase_115 | AC | 3 ms
6,940 KB |
testcase_116 | WA | - |
testcase_117 | AC | 3 ms
6,944 KB |
testcase_118 | AC | 2 ms
6,944 KB |
testcase_119 | AC | 2 ms
6,944 KB |
testcase_120 | AC | 3 ms
6,940 KB |
testcase_121 | AC | 3 ms
6,940 KB |
testcase_122 | AC | 2 ms
6,944 KB |
testcase_123 | AC | 3 ms
6,944 KB |
testcase_124 | AC | 3 ms
6,944 KB |
testcase_125 | WA | - |
testcase_126 | AC | 3 ms
6,944 KB |
testcase_127 | WA | - |
testcase_128 | AC | 3 ms
6,944 KB |
testcase_129 | AC | 3 ms
6,948 KB |
testcase_130 | AC | 3 ms
6,944 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 | 3 ms
6,940 KB |
testcase_137 | WA | - |
testcase_138 | AC | 3 ms
6,940 KB |
testcase_139 | AC | 3 ms
6,944 KB |
testcase_140 | AC | 2 ms
6,940 KB |
testcase_141 | AC | 3 ms
6,944 KB |
testcase_142 | AC | 3 ms
6,940 KB |
ソースコード
#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, 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, 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"; }