Submission #73908776
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
#define INF 1e18
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl "\n"
#define vi vector<int>
#define vs vector<string>
#define pii pair<int, int>
#define mii map<int, int>
#define seti set<int>
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define pr(a) cout<<a<<endl;
#define printList(a) for (auto &x : a) cout << x << " ";cout<<endl;
#define printMap(a) for (auto &x : a) cout << x.ff << " " << x.ss << endl;
#define PI 3.1415926535897932384626
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define w(x) int x; cin>>x; while(x--)
#define sortall(x) sort(all(x))
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vpii vector<pii>
#define matrix(N,M) vvi matrix(N, vi(M, 0));
#define printMatrix(matrix) for(auto &x:matrix){for(auto &y:x)cout<<y<<" ";cout<<endl;}
#define inputMatrix(matrix) for(auto &x:matrix)for(auto &y:x)cin>>y;
#define sortMatrix(matrix) for(auto &x:matrix)sortall(x);
#define rotateMatrix(matrix) reverse(all(matrix));for(int i=0;i<matrix.size();i++)for(int j=0;j<i;j++)swap(matrix[i][j],matrix[j][i]);
#define matrixSum(matrix) int sum=0;for(auto &x:matrix)for(auto &y:x)sum+=y;cout<<sum<<endl;
#define matrixProduct(matrix) int product=1;for(auto &x:matrix)for(auto &y:x)product*=y;cout<<product<<endl;
#define matrixMax(matrix) int mx=INT_MIN;for(auto &x:matrix)for(auto &y:x)mx=max(mx,y);cout<<mx<<endl;
#define matrixMin(matrix) int mn=INT_MAX;for(auto &x:matrix)for(auto &y:x)mn=min(mn,y);cout<<mn<<endl;
#define matrixTranspose(matrix) for(int i=0;i<matrix.size();i++)for(int j=0;j<i;j++)swap(matrix[i][j],matrix[j][i]);
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define maxEle(a) *max_element(all(a))
#define minEle(a) *min_element(all(a))
#define sumEle(a) accumulate(all(a),0)
#define productEle(a) accumulate(all(a),1,multiplies<int>())
#define maxIndex(a) max_element(all(a))-a.begin()
#define minIndex(a) min_element(all(a))-a.begin()
#define findIndex(a,x) find(all(a),x)-a.begin()
#define findEle(a,x) find(all(a),x)!=a.end()
#define countEle(a,x) count(all(a),x)
#define lowerEle(a,x) lower_bound(all(a),x)-a.begin()
#define upperEle(a,x) upper_bound(all(a),x)-a.begin()
#define gcd(a,b) __gcd(a,b)
#define hi cout<<"Hello\n";
#define yes cout<<"Yes\n";
#define no cout<<"No\n";
int Binary_exp(int a, int b, int c ){
int ans = 1;
while(b){
if(b&1){
ans =(ans*1LL*a) % c;
}
a = (a*1LL*a) % c;
b/=2;
}
return ans;
}
int C(int n, int r) { if (r > n - r) r = n - r; int ans = 1; for (int i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; }
int modInv(int a) { return Binary_exp(a, MOD - 2, MOD); }
bool isPrime(int n){ if(n<=1)return false; for(int i=2;i*i<=n;i++)if(n%i==0)return false; return true; }
template<class T>ostream &operator<<(ostream &os,const vector<T> &p){for(auto &it:p)os<<it<<' ';return os;}
template<class T>void dbs(string str,T t){cerr<<str<<":"<<t<<endl;}
template<class T,class...S>void dbs(string str,T t,S... s){int idx=str.find(',');cerr<<str.substr(0,idx)<<":"<<t<<",";dbs(str.substr(idx+1),s...);}
const int max_n = 200005;
vector<int> adj[max_n];
int a[max_n];
string ans[max_n];
map<int, int> cnt;
void dfs(int u, int p, bool flag) {
cnt[a[u]]++;
bool flag1 = flag || (cnt[a[u]] > 1);
if (flag1) {
ans[u] = "Yes";
} else {
ans[u] = "No";
}
for (int v : adj[u]) {
if (v != p) {
dfs(v, u, flag1);
}
}
// backtrack
cnt[a[u]]--;
}
void solved(){
int n;
cin>>n;
for (int i = 1; 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);
}
dfs(1, 0, false);
for (int i = 1; i <= n; i++) {
cout << ans[i] << "\n";
}
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin>>t;
while(t--){
solved();
}
return 0;
}
Submission Info
| Submission Time |
|
| Task |
D - Integer-duplicated Path |
| User |
s_mtCF |
| Language |
C++23 (GCC 15.2.0) |
| Score |
400 |
| Code Size |
4605 Byte |
| Status |
AC |
| Exec Time |
223 ms |
| Memory |
53372 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 |
178 ms |
39796 KiB |
| hack_02.txt |
AC |
170 ms |
39716 KiB |
| hack_03.txt |
AC |
45 ms |
26452 KiB |
| hack_04.txt |
AC |
44 ms |
26448 KiB |
| hack_05.txt |
AC |
110 ms |
36524 KiB |
| hack_06.txt |
AC |
109 ms |
36644 KiB |
| sample_01.txt |
AC |
5 ms |
12644 KiB |
| sample_02.txt |
AC |
5 ms |
12796 KiB |
| sample_03.txt |
AC |
5 ms |
12672 KiB |
| test_01.txt |
AC |
4 ms |
12628 KiB |
| test_02.txt |
AC |
4 ms |
12628 KiB |
| test_03.txt |
AC |
223 ms |
53244 KiB |
| test_04.txt |
AC |
221 ms |
53296 KiB |
| test_05.txt |
AC |
212 ms |
53372 KiB |
| test_06.txt |
AC |
184 ms |
48208 KiB |
| test_07.txt |
AC |
80 ms |
40832 KiB |
| test_08.txt |
AC |
74 ms |
40788 KiB |
| test_09.txt |
AC |
152 ms |
38984 KiB |
| test_10.txt |
AC |
153 ms |
38988 KiB |
| test_11.txt |
AC |
152 ms |
38756 KiB |
| test_12.txt |
AC |
120 ms |
30560 KiB |
| test_13.txt |
AC |
48 ms |
26504 KiB |
| test_14.txt |
AC |
44 ms |
26368 KiB |
| test_15.txt |
AC |
182 ms |
39880 KiB |
| test_16.txt |
AC |
181 ms |
39880 KiB |
| test_17.txt |
AC |
175 ms |
39780 KiB |
| test_18.txt |
AC |
171 ms |
38516 KiB |
| test_19.txt |
AC |
66 ms |
27600 KiB |
| test_20.txt |
AC |
64 ms |
27644 KiB |
| test_21.txt |
AC |
184 ms |
40712 KiB |
| test_22.txt |
AC |
161 ms |
39196 KiB |
| test_23.txt |
AC |
165 ms |
39492 KiB |
| test_24.txt |
AC |
123 ms |
29596 KiB |
| test_25.txt |
AC |
59 ms |
27380 KiB |
| test_26.txt |
AC |
53 ms |
27612 KiB |
| test_27.txt |
AC |
214 ms |
50128 KiB |
| test_28.txt |
AC |
189 ms |
43644 KiB |
| test_29.txt |
AC |
200 ms |
49680 KiB |
| test_30.txt |
AC |
169 ms |
43216 KiB |
| test_31.txt |
AC |
72 ms |
34548 KiB |
| test_32.txt |
AC |
72 ms |
36352 KiB |
| test_33.txt |
AC |
201 ms |
44924 KiB |
| test_34.txt |
AC |
216 ms |
50076 KiB |
| test_35.txt |
AC |
196 ms |
47432 KiB |
| test_36.txt |
AC |
143 ms |
34376 KiB |
| test_37.txt |
AC |
79 ms |
38780 KiB |
| test_38.txt |
AC |
67 ms |
29776 KiB |