Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector<int> adjlst[100005];
- void CreateGraph(vector<int> &A,vector<int> &B){
- int n=A.size();
- for(int i=0;i<n;i++){
- adjlst[A[i]].push_back(B[i]);
- adjlst[B[i]].push_back(A[i]);
- }
- }
- int res=0;
- int dfs(int v,int p){
- int ans=0;
- for(auto i:adjlst[v]){
- if(i!=p){
- int x=dfs(i,v);
- ans+=x;
- res+=ceil((float)x/5);
- }
- }
- return ans+1;
- }
- int solution(vector<int> &A,vector<int> &B){
- CreateGraph(A,B);
- int ans=dfs(0,-1);
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment