Submission #73920340
Source Code Expand
#include <bits/stdc++.h>
#define ll long long
const ll N = 2e5 + 5, MOD = 998244353, inf = 2e18;
using namespace std;
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
char di[] = {'R', 'L', 'D', 'U'};
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
void Ebraam() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("Input.txt", "r", stdin);
freopen("Output.txt", "w", stdout);
#endif
}
void solve() {
int n;
cin >> n;
vector<int> adj[n + 5], a(n), ans(n + 1, 0);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
map<int, int> mp;
int cnt = 0;
function<void(int, int)> dfs = [&](int u, int p)-> void {
mp[a[u - 1]]++;
cnt += mp[a[u - 1]] == 2;
ans[u] |= cnt;
for (auto v: adj[u]) {
if (v == p)continue;
dfs(v, u);
}
if (mp[a[u - 1]] == 2)cnt--;
mp[a[u - 1]]--;
};
dfs(1, -1);
for (int i = 1; i <= n; i++) {
cout << (ans[i] ? "Yes" : "No") << '\n';
}
}
int main() {
Ebraam();
int t = 1;
// cin >> t;
while (t--) {
solve();
if (t)cout << endl;
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Integer-duplicated Path |
| User | Ebraam_Yousef |
| Language | C++23 (GCC 15.2.0) |
| Score | 400 |
| Code Size | 1729 Byte |
| Status | AC |
| Exec Time | 285 ms |
| Memory | 40824 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt |
| All | hack_01.txt, hack_02.txt, hack_03.txt, hack_04.txt, hack_05.txt, hack_06.txt, sample_01.txt, sample_02.txt, sample_03.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| hack_01.txt | AC | 206 ms | 28764 KiB |
| hack_02.txt | AC | 203 ms | 28920 KiB |
| hack_03.txt | AC | 49 ms | 16536 KiB |
| hack_04.txt | AC | 49 ms | 16608 KiB |
| hack_05.txt | AC | 139 ms | 26432 KiB |
| hack_06.txt | AC | 139 ms | 26384 KiB |
| sample_01.txt | AC | 1 ms | 3544 KiB |
| sample_02.txt | AC | 1 ms | 3552 KiB |
| sample_03.txt | AC | 1 ms | 3592 KiB |
| test_01.txt | AC | 1 ms | 3600 KiB |
| test_02.txt | AC | 1 ms | 3408 KiB |
| test_03.txt | AC | 273 ms | 40788 KiB |
| test_04.txt | AC | 285 ms | 40824 KiB |
| test_05.txt | AC | 275 ms | 40752 KiB |
| test_06.txt | AC | 252 ms | 36928 KiB |
| test_07.txt | AC | 93 ms | 31400 KiB |
| test_08.txt | AC | 85 ms | 31440 KiB |
| test_09.txt | AC | 180 ms | 25932 KiB |
| test_10.txt | AC | 183 ms | 26032 KiB |
| test_11.txt | AC | 182 ms | 26076 KiB |
| test_12.txt | AC | 150 ms | 19900 KiB |
| test_13.txt | AC | 56 ms | 16800 KiB |
| test_14.txt | AC | 48 ms | 16696 KiB |
| test_15.txt | AC | 212 ms | 25168 KiB |
| test_16.txt | AC | 211 ms | 25156 KiB |
| test_17.txt | AC | 207 ms | 25140 KiB |
| test_18.txt | AC | 211 ms | 24036 KiB |
| test_19.txt | AC | 73 ms | 15824 KiB |
| test_20.txt | AC | 68 ms | 15916 KiB |
| test_21.txt | AC | 207 ms | 26752 KiB |
| test_22.txt | AC | 193 ms | 25640 KiB |
| test_23.txt | AC | 188 ms | 26452 KiB |
| test_24.txt | AC | 145 ms | 18692 KiB |
| test_25.txt | AC | 64 ms | 16464 KiB |
| test_26.txt | AC | 60 ms | 17364 KiB |
| test_27.txt | AC | 257 ms | 36816 KiB |
| test_28.txt | AC | 230 ms | 30120 KiB |
| test_29.txt | AC | 271 ms | 36416 KiB |
| test_30.txt | AC | 226 ms | 31488 KiB |
| test_31.txt | AC | 80 ms | 24256 KiB |
| test_32.txt | AC | 80 ms | 26152 KiB |
| test_33.txt | AC | 236 ms | 31272 KiB |
| test_34.txt | AC | 257 ms | 37072 KiB |
| test_35.txt | AC | 248 ms | 34024 KiB |
| test_36.txt | AC | 196 ms | 22336 KiB |
| test_37.txt | AC | 92 ms | 29120 KiB |
| test_38.txt | AC | 75 ms | 19408 KiB |