結果
問題 | No.2822 Lights Up! (Tree Edition) |
ユーザー |
![]() |
提出日時 | 2024-07-26 22:33:38 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,701 bytes |
コンパイル時間 | 1,757 ms |
コンパイル使用メモリ | 146,776 KB |
実行使用メモリ | 9,600 KB |
最終ジャッジ日時 | 2024-07-26 22:33:45 |
合計ジャッジ時間 | 6,500 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 43 ms
9,472 KB |
testcase_03 | WA | - |
testcase_04 | AC | 43 ms
9,312 KB |
testcase_05 | AC | 45 ms
9,344 KB |
testcase_06 | AC | 44 ms
9,344 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 38 ms
9,088 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 25 ms
6,940 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 3 ms
6,940 KB |
testcase_18 | WA | - |
testcase_19 | AC | 3 ms
6,940 KB |
testcase_20 | AC | 4 ms
6,944 KB |
testcase_21 | WA | - |
testcase_22 | AC | 4 ms
6,940 KB |
testcase_23 | AC | 4 ms
6,944 KB |
testcase_24 | AC | 4 ms
6,944 KB |
testcase_25 | WA | - |
testcase_26 | AC | 4 ms
6,940 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 3 ms
6,940 KB |
testcase_32 | AC | 5 ms
6,940 KB |
testcase_33 | AC | 5 ms
6,940 KB |
testcase_34 | WA | - |
testcase_35 | AC | 5 ms
6,940 KB |
testcase_36 | WA | - |
testcase_37 | AC | 5 ms
6,944 KB |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | AC | 5 ms
6,944 KB |
testcase_42 | AC | 5 ms
6,940 KB |
testcase_43 | AC | 5 ms
6,940 KB |
testcase_44 | AC | 5 ms
6,940 KB |
testcase_45 | AC | 5 ms
6,944 KB |
testcase_46 | AC | 6 ms
6,944 KB |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | AC | 3 ms
6,940 KB |
testcase_52 | AC | 2 ms
6,940 KB |
testcase_53 | WA | - |
testcase_54 | AC | 2 ms
6,944 KB |
testcase_55 | WA | - |
testcase_56 | AC | 2 ms
6,944 KB |
testcase_57 | AC | 2 ms
6,948 KB |
testcase_58 | AC | 2 ms
6,944 KB |
testcase_59 | AC | 2 ms
6,940 KB |
testcase_60 | AC | 2 ms
6,944 KB |
testcase_61 | WA | - |
testcase_62 | WA | - |
testcase_63 | AC | 2 ms
6,940 KB |
testcase_64 | AC | 2 ms
6,944 KB |
testcase_65 | AC | 2 ms
6,944 KB |
testcase_66 | WA | - |
testcase_67 | WA | - |
testcase_68 | WA | - |
testcase_69 | WA | - |
testcase_70 | WA | - |
testcase_71 | AC | 2 ms
6,940 KB |
testcase_72 | WA | - |
testcase_73 | WA | - |
testcase_74 | AC | 2 ms
6,944 KB |
testcase_75 | AC | 2 ms
6,944 KB |
testcase_76 | WA | - |
testcase_77 | WA | - |
testcase_78 | WA | - |
testcase_79 | AC | 2 ms
6,944 KB |
testcase_80 | WA | - |
testcase_81 | WA | - |
testcase_82 | AC | 2 ms
6,944 KB |
testcase_83 | WA | - |
testcase_84 | AC | 2 ms
6,940 KB |
testcase_85 | AC | 1 ms
6,944 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 | WA | - |
testcase_91 | WA | - |
testcase_92 | AC | 2 ms
6,940 KB |
testcase_93 | WA | - |
testcase_94 | WA | - |
testcase_95 | AC | 1 ms
6,940 KB |
testcase_96 | AC | 2 ms
6,940 KB |
testcase_97 | AC | 2 ms
6,940 KB |
testcase_98 | WA | - |
testcase_99 | AC | 2 ms
6,944 KB |
testcase_100 | WA | - |
testcase_101 | WA | - |
testcase_102 | WA | - |
testcase_103 | AC | 2 ms
6,944 KB |
testcase_104 | AC | 2 ms
6,944 KB |
testcase_105 | WA | - |
testcase_106 | WA | - |
testcase_107 | WA | - |
testcase_108 | WA | - |
testcase_109 | WA | - |
testcase_110 | WA | - |
testcase_111 | WA | - |
testcase_112 | AC | 2 ms
6,940 KB |
testcase_113 | AC | 2 ms
6,940 KB |
testcase_114 | WA | - |
testcase_115 | WA | - |
testcase_116 | AC | 2 ms
6,944 KB |
testcase_117 | WA | - |
testcase_118 | AC | 2 ms
6,940 KB |
testcase_119 | AC | 2 ms
6,944 KB |
testcase_120 | WA | - |
testcase_121 | WA | - |
testcase_122 | WA | - |
testcase_123 | AC | 2 ms
6,940 KB |
testcase_124 | WA | - |
testcase_125 | WA | - |
testcase_126 | AC | 2 ms
6,940 KB |
testcase_127 | WA | - |
testcase_128 | AC | 2 ms
6,944 KB |
testcase_129 | WA | - |
testcase_130 | WA | - |
testcase_131 | AC | 2 ms
6,944 KB |
testcase_132 | WA | - |
testcase_133 | AC | 2 ms
6,940 KB |
testcase_134 | AC | 2 ms
6,944 KB |
testcase_135 | WA | - |
testcase_136 | AC | 2 ms
6,940 KB |
testcase_137 | WA | - |
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 | AC | 2 ms
6,944 KB |
testcase_143 | AC | 2 ms
6,940 KB |
ソースコード
#include <string.h> #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; template <typename T> using vc = vector<T>; template <typename T> using vvc = vector<vector<T>>; template <typename T> using vvvc = vector<vector<vector<T>>>; template<class T> using pq = priority_queue<T,vector<T>,greater<T>>; template <class T, class S> inline bool chmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); } template <class T, class S> inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); } int dx4[] = {1,0,-1,0}; int dy4[] = {0,1,0,-1}; #define overload5(a, b, c, d, e, name, ...) name #define overload4(a, b, c, d, name, ...) name #define REP0(n) for(ll jidlsjf = 0; jidlsjf < n; ++jidlsjf) #define REP1(i, n) for(ll i = 0; i < (n); ++i) #define REP2(i, a, b) for(ll i = (a); i < (b); ++i) #define REP3(i, a, b, c) for(ll i = (a); i < (b); i += (c)) #define rep(...) overload4(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__) #define per0(n) for(int jidlsjf = 0; jidlsjf < (n); ++jidlsjf) #define per1(i, n) for(ll i = (n)-1; i >= 0; --i) #define per2(i, a, b) for(ll i = (a)-1; i >= b; --i) #define per3(i, a, b, c) for(ll i = (a)-1; i >= (b); i -= (c)) #define per(...) overload4(__VA_ARGS__, per3, per2, per1, per0)(__VA_ARGS__) #define setbits(j, n) for(ll iiiii = (n), j = lowbit(iiiii); iiiii; iiiii ^= 1 << j, j = lowbit(iiiii)) #define perm(v) for(bool permrepflag = true; (permrepflag ? exchange(permrepflag, false) : next_permutation(all(v)));) #define fi first #define se second #define pb push_back #define ppb pop_back #define ppf pop_front #define drop(s) cout << #s << endl, exit(0) #define si(c) (int)(c).size() #define lb(c, x) distance((c).begin(), lower_bound(all(c), (x))) #define lbg(c, x) distance((c).begin(), lower_bound(all(c), (x), greater{})) #define ub(c, x) distance((c).begin(), upper_bound(all(c), (x))) #define ubg(c, x) distance((c).begin(), upper_bound(all(c), (x), greater{})) #define rng(v, l, r) v.begin() + (l), v.begin() + (r) #define all(c) c.begin(), c.end() #define rall(c) c.rbegin(), c.rend() #define SORT(v) sort(all(v)) #define REV(v) reverse(all(v)) #define UNIQUE(x) SORT(x), x.erase(unique(all(x)), x.end()) #define MIN(v) *min_element(all(v)) #define MAX(v) *max_element(all(v)) #define overload2(_1, _2, name, ...) name #define vec(type, name, ...) vector<type> name(__VA_ARGS__) #define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__)) #define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__))) struct UnionFind { vector<int> par; vector<int> size; UnionFind() {} UnionFind(int n) { par.resize(n); size.resize(n,1); for(int i = 0; i < n; i++) { par[i] = i; } } int find(int x) { if(par[x] == x) { return x; } return par[x] = find(par[x]); } bool same(int x, int y) { return find(x) == find(y); } int consize(int x) { return size[find(x)]; } bool unite(int x, int y) { x = find(x); y = find(y); if(x == y) { return false; } if(size[x] > size[y]) { swap(x,y); } par[x] = y; size[y] += size[x]; return true; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vc<int>P(N,-1); vvc<int>ki(N); rep(i,1,N) { cin >> P[i]; P[i]--; ki[P[i]].pb(i); } string S; cin >> S; UnionFind uf(N); int K; cin >> K; rep(i,K) { int u,v; cin >> u >> v; u--; v--; uf.unite(u,v); } vc<int>res(N); auto dfs = [&](auto &dfs,int n) -> int { int f = 0; for(auto i:ki[n]) { f ^= dfs(dfs,i); } if(n) { f ^= (S[n-1] == '#'); res[uf.find(n)] ^= f; } return f; }; dfs(dfs,0); rep(i,N) { if(res[i] && !uf.same(0,i)) { cout << "No" << "\n"; return 0; } } cout << "Yes" << "\n"; }