답안 #478748

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478748 2021-10-08T08:27:46 Z stefantaga Arboras (RMI20_arboras) C++14
0 / 100
5000 ms 8732 KB
#include <bits/stdc++.h>
#define MOD 1000000007
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 sum,inainte;
void updateaza(int poz,int nod)
{
    if (ceau[poz].first==nod)
    {
        inainte=val[poz];
        haide(poz);
        sum=(sum+(val[poz]%MOD)-(inainte%MOD)+MOD)%MOD;
    }
    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;
        }
        inainte=val[poz];
        haide(poz);
        sum=(sum+(val[poz]%MOD)-(inainte%MOD)+MOD)%MOD;
    }
    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;
            }
        }
        inainte=val[poz];
        haide(poz);
        sum=(sum+(val[poz]%MOD)-(inainte%MOD)+MOD)%MOD;
    }
}
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<<sum<<'\n';
    int q,x,y;
    cin>>q;
    for (i=1;i<=q;i++)
    {
        cin>>x>>y;
        x++;
        cost[x]+=y;
        while (x!=1)
        {
            updateaza(tata[x],x);
            x=tata[x];
        }
        cout<<sum<<'\n';
    }
    return 0;
}

Compilation message

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