INOI 2016 Discussion

In the month of May

last year it was from 1st to 9th may

1 Like

I tried three time to edit β€œ&lt” means β€œ<” and β€œ&gt” means β€œ>”

It probably is too much memory. Use int instead of long long

@mathecodician It’s the same even after using int instead of long long

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mx=INT_MIN;
void dfs(vector<ll> adj[],ll parent,bool visited[],ll A[])
{
    if(visited[parent])
    return;
    visited[parent]=true;
    for(auto u:adj[parent])
    {
        if((A[parent]-A[u])>mx)
        mx=(A[parent]-A[u]);
        dfs(adj,u,visited,A);
    }
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

    ll n,i,parent;
    cin>>n;
    ll A[n+1],P[n+1];
    bool visited[n+1];
    for(i=1;i<=n;i++)
    {cin>>A[i];visited[i]=false;}
    for(i=1;i<=n;i++)
    {
        cin>>P[i];
        if(P[i]==-1)
        parent=i;
    }
    vector<ll> adj[n+1];
    for(i=1;i<=n;i++)
    {
        if(P[i]!=-1)
        adj[P[i]].push_back(i);
    }


    dfs(adj,parent,visited,A);
    cout<<mx;
}

can anyone tell me whats wrong with my code?