Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Task : _example
- Author : Phumipat C. [MAGCARI]
- Language: C++
- Created : 26 February 2023 [09:06]
- */
- #include<bits/stdc++.h>
- using namespace std;
- vector<int > g[1010];
- map<int ,int > cnt[1010];
- int col[1010];
- // cnt[i][j] is the number of vertices in subtree of vertex i that has color j
- void dfs(int u,int p){
- int mx = -1,bigChild = -1;
- for(auto x:g[u]){
- if(x == p) continue;
- dfs(x,u);
- if(mx < cnt[x].size()){
- mx = cnt[x].size();
- bigChild = x;
- }
- }
- if(bigChild != -1)
- cnt[u] = cnt[bigChild];
- cnt[u][col[u]]++;
- for(auto x:g[u]){
- if(x == p || x == bigChild) continue;
- for(auto y:cnt[x])
- cnt[u][y.first]+=y.second;
- }
- }
- int main(){
- cin.tie(0)->sync_with_stdio(0);
- cin.exceptions(cin.failbit);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment