Submission #21691565


Source Code Expand

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/













int N, C[101010];
vector<int> E[101010];
//---------------------------------------------------------------------------------------------------
int cnt[101010];
bool good[101010];
void dfs(int cu, int pa = -1) {
    if (cnt[C[cu]] == 0) good[cu] = true;
    cnt[C[cu]]++;

    fore(to, E[cu]) if (to != pa) {
        dfs(to, cu);
    }

    cnt[C[cu]]--;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> C[i];
    rep(i, 0, N - 1) {
        int a, b; cin >> a >> b;
        a--; b--;
        E[a].push_back(b);
        E[b].push_back(a);
    }

    dfs(0);
    rep(i, 0, N) if(good[i]) printf("%d\n", i + 1);
}





Submission Info

Submission Time
Task E - Unique Color
User hamayanhamayan
Language C++ (GCC 9.2.1)
Score 500
Code Size 2033 Byte
Status AC
Exec Time 63 ms
Memory 16260 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 29
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All binary_01.txt, binary_02.txt, binary_03.txt, binary_04.txt, binary_05.txt, min_01.txt, min_02.txt, path_01.txt, path_02.txt, path_03.txt, path_04.txt, path_05.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, sample_01.txt, sample_02.txt, star_01.txt, star_02.txt, star_03.txt, star_04.txt, star_05.txt
Case Name Status Exec Time Memory
binary_01.txt AC 51 ms 9516 KiB
binary_02.txt AC 50 ms 9568 KiB
binary_03.txt AC 50 ms 9588 KiB
binary_04.txt AC 58 ms 10116 KiB
binary_05.txt AC 55 ms 10080 KiB
min_01.txt AC 5 ms 5876 KiB
min_02.txt AC 8 ms 5892 KiB
path_01.txt AC 53 ms 15700 KiB
path_02.txt AC 56 ms 15700 KiB
path_03.txt AC 51 ms 15784 KiB
path_04.txt AC 57 ms 16260 KiB
path_05.txt AC 63 ms 16212 KiB
random_01.txt AC 9 ms 6128 KiB
random_02.txt AC 6 ms 5988 KiB
random_03.txt AC 6 ms 6100 KiB
random_04.txt AC 8 ms 6368 KiB
random_05.txt AC 8 ms 6080 KiB
random_06.txt AC 52 ms 9500 KiB
random_07.txt AC 49 ms 9644 KiB
random_08.txt AC 51 ms 9804 KiB
random_09.txt AC 56 ms 9928 KiB
random_10.txt AC 55 ms 10128 KiB
sample_01.txt AC 6 ms 6136 KiB
sample_02.txt AC 5 ms 6016 KiB
star_01.txt AC 43 ms 9716 KiB
star_02.txt AC 51 ms 9728 KiB
star_03.txt AC 48 ms 9772 KiB
star_04.txt AC 47 ms 10120 KiB
star_05.txt AC 51 ms 9912 KiB