Submission #242273

# Submission time Handle Problem Language Result Execution time Memory
242273 2020-06-27T07:58:31 Z tqbfjotld Magic Tree (CEOI19_magictree) C++14
14 / 100
86 ms 8056 KB
/*
subtask 1 - brute force
subtask 2 - take all
subtask 3 - lds
subtask 4 - dp on tree, day1-day2
*/

#include <bits/stdc++.h>
using namespace std;

int n,m,k;
int p[100005];
int d[100005];
long long w[100005];
vector<int> adjl[100005];
long long tot[100005];

long long func(int node){
    if (adjl[node].size()==0){
        tot[node] = d[node]==1?w[node]:-w[node];
        return max(0LL,tot[node]);
    }
    long long ans = 0;
    for (auto x : adjl[node]){
        ans += func(x);
        tot[node] += tot[x];
    }
    tot[node] += d[node]==1?w[node]:-w[node];
    return max(ans,tot[node]);



}

int main(){
    scanf("%d%d%d",&n,&m,&k);
    bool subtask3 = true;
    for (int x = 1; x<n; x++){
        scanf("%d",&p[x]);
        p[x]--;
        if (p[x]!=x-1) subtask3 = false;
        adjl[p[x]].push_back(x);
    }
    long long temps=0;
    for (int x = 0; x<m; x++){
        int a,b;
        long long c;
        scanf("%d%d%lld",&a,&b,&c);
        a--;
        d[a] = b;
        w[a] = c;
        if (w[a]!=1) subtask3 = false;
        if (d[x]==2) temps+=w[x];
    }
    if (k<=2){
        printf("%lld",func(0)+temps);
    }
    else if (subtask3){
        vector<int> v;
        for (int x = 0; x<n; x++){
            if (w[x]==0) continue;
            if (v.empty()) v.push_back(-d[x]);
            else if (-d[x]>=v[(int)v.size()-1]){
                v.push_back(-d[x]);
            }
            else{
                int pos = upper_bound(v.begin(),v.end(),-d[x])-v.begin();
                v[pos] = -d[x];
            }
        }
        printf("%d",v.size());
    }
    else{
        long long ans = 0;
        for (int x = 0; x<n; x++){
            ans += w[x];
        }
        printf("%lld",ans);
    }
}

Compilation message

magictree.cpp: In function 'int main()':
magictree.cpp:71:29: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
         printf("%d",v.size());
                     ~~~~~~~~^
magictree.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d",&n,&m,&k);
     ~~~~~^~~~~~~~~~~~~~~~~~~
magictree.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&p[x]);
         ~~~~~^~~~~~~~~~~~
magictree.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%lld",&a,&b,&c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 5632 KB Output is correct
2 Correct 37 ms 5760 KB Output is correct
3 Correct 63 ms 4984 KB Output is correct
4 Correct 56 ms 4728 KB Output is correct
5 Correct 62 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2736 KB Output is correct
3 Correct 7 ms 2816 KB Output is correct
4 Correct 61 ms 7288 KB Output is correct
5 Correct 59 ms 8056 KB Output is correct
6 Correct 65 ms 7416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 86 ms 6764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 3328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -