結果

問題 No.2822 Lights Up! (Tree Edition)
ユーザー 👑 AngrySadEightAngrySadEight
提出日時 2024-07-03 21:52:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 4,348 bytes
コンパイル時間 5,667 ms
コンパイル使用メモリ 228,492 KB
実行使用メモリ 16,128 KB
最終ジャッジ日時 2024-07-03 21:52:40
合計ジャッジ時間 11,766 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 115 ms
16,128 KB
testcase_02 AC 112 ms
16,000 KB
testcase_03 AC 113 ms
16,000 KB
testcase_04 AC 114 ms
16,000 KB
testcase_05 AC 115 ms
16,000 KB
testcase_06 AC 125 ms
16,000 KB
testcase_07 AC 65 ms
8,192 KB
testcase_08 AC 103 ms
15,360 KB
testcase_09 AC 85 ms
11,520 KB
testcase_10 AC 59 ms
10,624 KB
testcase_11 AC 73 ms
8,960 KB
testcase_12 AC 50 ms
6,940 KB
testcase_13 AC 63 ms
10,112 KB
testcase_14 AC 76 ms
9,984 KB
testcase_15 AC 4 ms
6,944 KB
testcase_16 AC 5 ms
6,944 KB
testcase_17 AC 10 ms
6,940 KB
testcase_18 AC 5 ms
6,940 KB
testcase_19 AC 6 ms
6,940 KB
testcase_20 AC 9 ms
6,940 KB
testcase_21 AC 8 ms
6,944 KB
testcase_22 AC 8 ms
6,944 KB
testcase_23 AC 7 ms
6,944 KB
testcase_24 AC 4 ms
6,944 KB
testcase_25 AC 8 ms
6,944 KB
testcase_26 AC 3 ms
6,940 KB
testcase_27 AC 8 ms
6,940 KB
testcase_28 AC 11 ms
6,944 KB
testcase_29 AC 8 ms
6,940 KB
testcase_30 AC 5 ms
6,940 KB
testcase_31 AC 12 ms
6,940 KB
testcase_32 AC 12 ms
6,940 KB
testcase_33 AC 11 ms
6,940 KB
testcase_34 AC 12 ms
6,940 KB
testcase_35 AC 12 ms
6,940 KB
testcase_36 AC 12 ms
6,940 KB
testcase_37 AC 12 ms
6,940 KB
testcase_38 AC 12 ms
6,940 KB
testcase_39 AC 12 ms
6,944 KB
testcase_40 AC 12 ms
6,944 KB
testcase_41 AC 12 ms
6,940 KB
testcase_42 AC 12 ms
6,940 KB
testcase_43 AC 11 ms
6,944 KB
testcase_44 AC 12 ms
6,944 KB
testcase_45 AC 11 ms
6,944 KB
testcase_46 AC 11 ms
6,940 KB
testcase_47 AC 3 ms
6,940 KB
testcase_48 AC 3 ms
6,940 KB
testcase_49 AC 3 ms
6,940 KB
testcase_50 AC 3 ms
6,940 KB
testcase_51 AC 3 ms
6,944 KB
testcase_52 AC 3 ms
6,940 KB
testcase_53 AC 2 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,944 KB
testcase_57 AC 3 ms
6,940 KB
testcase_58 AC 3 ms
6,944 KB
testcase_59 AC 3 ms
6,940 KB
testcase_60 AC 2 ms
6,940 KB
testcase_61 AC 2 ms
6,944 KB
testcase_62 AC 2 ms
6,944 KB
testcase_63 AC 3 ms
6,944 KB
testcase_64 AC 3 ms
6,940 KB
testcase_65 AC 3 ms
6,940 KB
testcase_66 AC 2 ms
6,940 KB
testcase_67 AC 3 ms
6,940 KB
testcase_68 AC 2 ms
6,940 KB
testcase_69 AC 2 ms
6,944 KB
testcase_70 AC 3 ms
6,944 KB
testcase_71 AC 3 ms
6,940 KB
testcase_72 AC 3 ms
6,940 KB
testcase_73 AC 2 ms
6,940 KB
testcase_74 AC 2 ms
6,944 KB
testcase_75 AC 3 ms
6,940 KB
testcase_76 AC 2 ms
6,940 KB
testcase_77 AC 2 ms
6,940 KB
testcase_78 AC 2 ms
6,940 KB
testcase_79 AC 2 ms
6,940 KB
testcase_80 AC 2 ms
6,940 KB
testcase_81 AC 2 ms
6,940 KB
testcase_82 AC 2 ms
6,940 KB
testcase_83 AC 2 ms
6,940 KB
testcase_84 AC 2 ms
6,944 KB
testcase_85 AC 2 ms
6,944 KB
testcase_86 AC 2 ms
6,940 KB
testcase_87 AC 2 ms
6,940 KB
testcase_88 AC 2 ms
6,940 KB
testcase_89 AC 2 ms
6,944 KB
testcase_90 AC 2 ms
6,944 KB
testcase_91 AC 2 ms
6,944 KB
testcase_92 AC 2 ms
6,944 KB
testcase_93 AC 2 ms
6,940 KB
testcase_94 AC 2 ms
6,940 KB
testcase_95 AC 2 ms
6,940 KB
testcase_96 AC 2 ms
6,940 KB
testcase_97 AC 2 ms
6,940 KB
testcase_98 AC 2 ms
6,944 KB
testcase_99 AC 2 ms
6,944 KB
testcase_100 AC 2 ms
6,940 KB
testcase_101 AC 2 ms
6,940 KB
testcase_102 AC 2 ms
6,940 KB
testcase_103 AC 2 ms
6,944 KB
testcase_104 AC 2 ms
6,944 KB
testcase_105 AC 2 ms
6,940 KB
testcase_106 AC 2 ms
6,944 KB
testcase_107 AC 2 ms
6,944 KB
testcase_108 AC 2 ms
6,944 KB
testcase_109 AC 2 ms
6,940 KB
testcase_110 AC 2 ms
6,944 KB
testcase_111 AC 2 ms
6,944 KB
testcase_112 AC 2 ms
6,940 KB
testcase_113 AC 2 ms
6,940 KB
testcase_114 AC 2 ms
6,940 KB
testcase_115 AC 2 ms
6,944 KB
testcase_116 AC 2 ms
6,944 KB
testcase_117 AC 2 ms
6,940 KB
testcase_118 AC 2 ms
6,940 KB
testcase_119 AC 2 ms
6,940 KB
testcase_120 AC 2 ms
6,940 KB
testcase_121 AC 2 ms
6,944 KB
testcase_122 AC 2 ms
6,944 KB
testcase_123 AC 2 ms
6,944 KB
testcase_124 AC 2 ms
6,940 KB
testcase_125 AC 3 ms
6,940 KB
testcase_126 AC 2 ms
6,944 KB
testcase_127 AC 2 ms
6,944 KB
testcase_128 AC 2 ms
6,940 KB
testcase_129 AC 2 ms
6,940 KB
testcase_130 AC 2 ms
6,940 KB
testcase_131 AC 2 ms
6,940 KB
testcase_132 AC 2 ms
6,940 KB
testcase_133 AC 3 ms
6,944 KB
testcase_134 AC 2 ms
6,944 KB
testcase_135 AC 2 ms
6,944 KB
testcase_136 AC 2 ms
6,944 KB
testcase_137 AC 2 ms
6,944 KB
testcase_138 AC 2 ms
6,944 KB
testcase_139 AC 2 ms
6,940 KB
testcase_140 AC 3 ms
6,944 KB
testcase_141 AC 2 ms
6,944 KB
testcase_142 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <atcoder/all>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define repk(i, k, n) for (int i = k; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define mod1 1000000007
#define mod2 998244353
#define mod3 100000007
#define vi vector<int>
#define vs vector<string>
#define vc vector<char>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vvl vector<vector<ll>>
#define vvb vector<vector<bool>>
#define vvvi vector<vector<vector<int>>>
#define vvvl vector<vector<vector<ll>>>
#define pii pair<int, int>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define vvpii vector<vector<pair<int, int>>>
#define vvpll vector<vector<pair<ll, ll>>>

using mint = modint998244353;

template <typename T>
void debug(T e) {
    cerr << e << endl;
}

template <typename T>
void debug(vector<T> &v) {
    rep(i, v.size()) { cerr << v[i] << " "; }
    cerr << endl;
}

template <typename T>
void debug(vector<vector<T>> &v) {
    rep(i, v.size()) {
        rep(j, v[i].size()) { cerr << v[i][j] << " "; }
        cerr << endl;
    }
}

template <typename T>
void debug(vector<pair<T, T>> &v) {
    rep(i, v.size()) { cerr << v[i].first << " " << v[i].second << endl; }
}

template <typename T>
void debug(set<T> &st) {
    for (auto itr = st.begin(); itr != st.end(); itr++) {
        cerr << *itr << " ";
    }
    cerr << endl;
}

template <typename T>
void debug(multiset<T> &ms) {
    for (auto itr = ms.begin(); itr != ms.end(); itr++) {
        cerr << *itr << " ";
    }
    cerr << endl;
}

template <typename T>
void debug(map<T, T> &mp) {
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        cerr << itr->first << " " << itr->second << endl;
    }
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << H << " ";
    debug_out(T...);
}

void dfs(vector<bool> &isvisited, vector<vector<pll>> &graph,
         vector<ll> &e_cols, vector<ll> &v_cols, ll v) {
    isvisited[v] = true;
    ll col = 0;
    ll next_col = 0;
    for (ll i = 0; i < graph[v].size(); i++) {
        ll x = graph[v][i].first;
        ll x_col = e_cols[graph[v][i].second];
        if (isvisited[x]) {
            col = x_col;
            continue;
        } else {
            next_col ^= x_col;
            dfs(isvisited, graph, e_cols, v_cols, x);
        }
    }
    v_cols[v] = col ^ next_col;
}

int main() {
    ll N;
    cin >> N;
    vector<ll> P(N - 1);
    for (ll i = 0; i < N - 1; i++) {
        cin >> P[i];
        P[i]--;
    }
    string S;
    cin >> S;
    vector<ll> e_cols(N - 1, 0);
    for (ll i = 0; i < N - 1; i++) {
        if (S[i] == '#') {
            e_cols[i] = 1;
        }
    }
    ll Q;
    cin >> Q;
    vector<ll> U(Q);
    vector<ll> V(Q);
    for (ll i = 0; i < Q; i++) {
        cin >> U[i] >> V[i];
        U[i]--;
        V[i]--;
    }
    vector<vector<pll>> graph(N, vector<pll>(0));
    for (ll i = 0; i < N - 1; i++) {
        graph[i + 1].push_back(pll(P[i], i));
        graph[P[i]].push_back(pll(i + 1, i));
    }
    vector<ll> v_cols(N, -1);
    vector<bool> isvisited(N, false);
    dfs(isvisited, graph, e_cols, v_cols, 0);
    // debug(v_cols);
    dsu tree(N);
    for (ll i = 0; i < Q; i++) {
        tree.merge(U[i], V[i]);
    }
    vector<ll> cc_cols(N, 0);
    for (ll i = 0; i < N; i++) {
        cc_cols[tree.leader(i)] += v_cols[i];
    }
    bool ans = true;
    for (ll i = 0; i < N; i++) {
        if (cc_cols[i] % 2 != 0) {
            ans = false;
        }
    }
    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
0