Submission #1020525

# Submission time Handle Problem Language Result Execution time Memory
1020525 2024-07-12T06:30:38 Z vjudge1 Making Friends on Joitter is Fun (JOI20_joitter2) C++
0 / 100
3 ms 7512 KB
#include <bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define ins insert
#define pf push_front
#define bit(n,k) ((n>>k)&1)
#define pi acos(-1.0)
const ll N=1e5+5, inf = 1e18, mod=1e9+7;
using namespace std;
vector<ll>v[N];
set<ll>s[N];
ll col[N],idx[N],ans[N];
void dfs(ll u, ll par){
    s[u].ins(col[u]);
    for(ll x:v[u]){
        if(x==par) continue;
        dfs(x,u);
        if(s[idx[x]].size()>s[idx[u]].size()){
            for(ll z:s[idx[u]]) s[idx[x]].ins(z);
            swap(idx[x],idx[u]);
        }
        else{
            for(ll z:s[idx[x]]) s[idx[u]].ins(z);
        }
    }
    ans[u]=s[idx[u]].size();
}
int main(){
    // freopen("TRAVEL.INP", "r", stdin);
    // freopen("TRAVEL.OUT", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,m,root; cin >>n >> m >> root;
    ll x,y;
    for(ll i=1;i<=n-1;i++){
        cin >> x >> y;
        v[x].pb(y);
        v[y].pb(x);
    }
    for(ll i=1;i<=n;i++) cin >> col[i],idx[i]=i;
    dfs(root,0);
    while(m--){
        ll x; cin >> x;
        cout << ans[x] << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7512 KB Output isn't correct
2 Halted 0 ms 0 KB -