Why this is wrong? Trying with stack DFS approach

#define mod 1000000007
#define ll long long int
int Solution::deleteEdge(vector<int> &A, vector<vector<int> > &B) {
    ll tot=0;
    ll mx=0;
    int n=A.size();
    for(int i=0;i<n;i++){
        tot+=A[i];
    }
    vector<int> adj[n+1];
    for(int i=0;i<B.size();i++){
        adj[B[i][0]].push_back(B[i][1]);
        adj[B[i][1]].push_back(B[i][0]);
    }
    for(int i=1;i<=1;i++){
        stack<pair<int,ll>> st;
        st.push({i,A[i-1]});
        vector<int> vis(n+1,0);
        vis[i]=1;
        while(!st.empty()){
            int v=st.top().first;
            ll sum=st.top().second%mod;
            st.pop();
            ll t1 = (tot-sum)%mod;
            mx=max(mx,(sum*t1)%mod);
            for(auto u:adj[v]){
                if(!vis[u]){
                    st.push({u,(sum+A[u-1])});
                    vis[u]=1;   
                }
            }
        }
    }
    return mx;
}
Click here to start solving coding interview questions