TLE problem, do not know why


#1

long int mod=1e9+7;
int mul_ans;
int sum;
int find_sum(vectorsol[],int mp[],vectorA,int source,int parent)
{ int i;

int max_sum=A[source-1];
for(i=0;i<sol[source].size();i++)
{
    if(sol[source][i]!=parent)
    {
        if(mp[sol[source][i]])
        max_sum=(max_sum%mod+mp[sol[source][i]]%mod)%mod;
        else
        max_sum=(max_sum%mod+find_sum(sol,mp,A,sol[source][i],source))%mod;
    }
    
}
mp[source]=max_sum%mod;
int val=sum-mp[source];
    int ans=((mp[source]%mod)*(val%mod))%mod;
    mul_ans=max(mul_ans,ans);
return mp[source]%mod;

}

int Solution::deleteEdge(vector &A, vector<vector > &B) {
vectorsol[100001];
int i,j;
mul_ans=0;
sum=0;
for(i=0;i<A.size();i++)
sum=sum+A[i];
for(i=0;i<B.size();i++)
{
sol[B[i][0]].push_back(B[i][1]);
sol[B[i][1]].push_back(B[i][0]);
}

int mp[100001]={0};
mp[1]=find_sum(sol,mp,A,1,-1);

return mul_ans;

}