結果

問題 No.2822 Lights Up! (Tree Edition)
ユーザー 🦠みどりむし
提出日時 2024-05-14 14:18:05
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 617 ms / 2,000 ms
コード長 833 bytes
コンパイル時間 3,413 ms
コンパイル使用メモリ 262,884 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-06-18 19:45:27
合計ジャッジ時間 15,641 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 142
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/dsu>

signed main() {
	int n; std::cin >> n;
	std::vector<int> p(n);
	for(int i : std::views::iota(1, n)) std::cin >> p[i], --p[i];
	std::valarray<bool> v(n);
	std::string s; std::cin >> s;
	for(int i : std::views::iota(1, n)) v[i] = s[i - 1] == '#';
	for(int x : v) std::cerr << x << " "; std::cerr << "\n";
	int q; std::cin >> q;
	atcoder::dsu ds(n);
	for(int i : std::views::iota(0, q)) {
		int x, y; std::cin >> x >> y; --x, --y;
		ds.merge(x, y);
	}
	for(int i : std::views::iota(1, n) | std::views::reverse) {
		v[p[i]] ^= s[i - 1] == '#';
	}
	
	for(int x : v) std::cerr << x << " ";
	
	auto groups = ds.groups();
	for(auto group : groups) {
		bool x = false;
		for(int i : group) x ^= v[i];
		if(x) {
			std::cout << "No" << "\n";
			return 0;
		}
	}

	std::cout << "Yes" << "\n";
}
0