Submission #242267

# Submission time Handle Problem Language Result Execution time Memory
242267 2020-06-27T07:55:03 Z tqbfjotld Magic Tree (CEOI19_magictree) C++14
14 / 100
75 ms 9976 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];
    }
    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);
    }
    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 (k<=2){
        printf("%lld",func(0));
    }
    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:68: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:35: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:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&p[x]);
         ~~~~~^~~~~~~~~~~~
magictree.cpp:46: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 41 ms 5624 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 7 ms 2688 KB Output is correct
2 Correct 6 ms 2816 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 58 ms 7288 KB Output is correct
5 Correct 57 ms 9976 KB Output is correct
6 Correct 64 ms 9336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 6648 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 -