/ SeriousOJ /

Record Detail

Compile Error

foo.cc: In function 'int main()':
foo.cc:65:27: error: 'arr' was not declared in this scope
   65 |         if(mx_dis<d[i] && arr[i]){
      |                           ^~~

Code

#include<bits/stdc++.h>
using namespace std;
const long long M=3e5+10,MOD=1000000000;
typedef long long ll;
vector<int>edge[M];
int level[M];
int d[M];
ll sum[M];
void dfs1(int x,int p){
    for(int u:edge[x]){
        if(u!=p){
            d[u]=d[x]+1;
            dfs1(u,x);
        }
    }
}
void dfs(int x,int p){
    for(int u:edge[x]){
        if(u!=p){
            d[u]=d[x]+1;
            dfs(u,x);
        }
    }
    level[p]+=level[x];
    sum[p]+=sum[x]+(2*min(1,level[x]));
    
}
void clear_edge(int n){
    for(int i=0;i<=n;i++){
        edge[i].clear();
        sum[i]=0;
        level[i]=0;
        d[i]=0;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--){
     int n;
     cin>>n;
     int cnt=0;
     clear_edge(n);
     for(int i=1;i<=n;i++){
        cin>>level[i];
        cnt+=level[i];
     }
     for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        edge[x].push_back(y);
        edge[y].push_back(x);
     }
     if(cnt<=1){
        cout<<0<<"\n";
        continue;
     }
     dfs(1,0);
     int cur=1;
     int mx_dis=0;
     for(int i=1;i<=n;i++){
        if(mx_dis<d[i] && arr[i]){
            mx_dis=d[i];
            cur=i;
        }
        d[i]=0;
     }
     dfs1(cur,0);
     ll maximum_dis=*max_element(d,d+n+1);
    

     

     

    }




    
   
   return 0;
 
}

Information

Submit By
Type
Submission
Problem
P1078 Apple on Tree
Language
C++20 (G++ 13.2.0)
Submit At
2024-07-29 22:18:39
Judged At
2024-10-03 13:34:13
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes