답안 #478739

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478739 2021-10-08T08:18:36 Z stefantaga Arboras (RMI20_arboras) C++14
0 / 100
5000 ms 11168 KB
#include <bits/stdc++.h>

using namespace std;
pair <int,int> ceau[100005];
long long val[100005],cost[100005];
void haide(int poz)
{
    val[poz]=val[ceau[poz].first]+cost[ceau[poz].first]+val[ceau[poz].second]+cost[ceau[poz].second];
}
long long maxim;
void updateaza(int poz,int nod)
{
    if (ceau[poz].first==nod)
    {
        haide(poz);
    }
    else
    if (ceau[poz].second==nod)
    {
        if (val[nod]+cost[nod]>val[ceau[poz].first]+cost[ceau[poz].first])
        {
            ceau[poz].second=ceau[poz].first;
            ceau[poz].first=nod;
        }
        haide(poz);
    }
    else
    {
        if (val[nod]+cost[nod]>val[ceau[poz].first]+cost[ceau[poz].first])
        {
            ceau[poz].second=ceau[poz].first;
            ceau[poz].first=nod;
        }
        else
        {
            if (val[nod]+cost[nod]>val[ceau[poz].second]+cost[ceau[poz].second])
            {
                ceau[poz].second=nod;
            }
        }
        haide(poz);
    }
    maxim=max(maxim,val[poz]);
}
vector <int> v[100005];
int loc;
void dfs(int x)
{
    for (int i=0;i<v[x].size();i++)
    {
        dfs(v[x][i]);
        loc=v[x][i];
        updateaza(x,loc);
    }
}
int n,i,tata[100005];
int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
    #ifdef HOME
    ifstream cin("date.in");
    ofstream cout("date.out");
    #endif // HOME
    cin>>n;
    for (i=2;i<=n;i++)
    {
        cin>>tata[i];
        tata[i]++;
        v[tata[i]].push_back(i);
    }
    for (i=2;i<=n;i++)
    {
        cin>>cost[i];
    }
    dfs(1);
    cout<<maxim<<'\n';
    int q,x,y;
    cin>>q;
    for (i=1;i<=q;i++)
    {
        cin>>x>>y;
        cost[x]+=y;
        while (x!=1)
        {
            updateaza(tata[x],x);
            x=tata[x];
        }
        cout<<maxim<<'\n';
    }
    return 0;
}

Compilation message

arboras.cpp: In function 'void dfs(int)':
arboras.cpp:49:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for (int i=0;i<v[x].size();i++)
      |                  ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 2768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 89 ms 10012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5080 ms 11168 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 2768 KB Output isn't correct
2 Halted 0 ms 0 KB -