답안 #242390

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
242390 2020-06-27T14:28:09 Z tqbfjotld Magic Tree (CEOI19_magictree) C++14
68 / 100
130 ms 28792 KB
#include <bits/stdc++.h>
using namespace std;

bool fruit[100005];
int day[100005];
int val[100005];
vector<int> adjl[100005];
int n,m,k;

map<int,int> func(int node){
    map<int,int> ans;
    if (adjl[node].size()>=1){
        ans = func(adjl[node][0]);
    }
    for (int x = 1; x<adjl[node].size(); x++){
        int ch = adjl[node][x];
        auto res = func(ch);
        if (res.size()>ans.size()){
            swap(res,ans);
        }
        for (auto item : res){
            ans[item.first] += item.second;
        }
    }
    if (fruit[node]){
        ans[day[node]] += val[node];
        int t = val[node];
        auto it = ans.upper_bound(day[node]);
        while (t>0&& it!=ans.end()){
            if ((*it).second<=t){
                t -= (*it).second;
                it = ans.erase(it);
            }
            else{
                ans[(*it).first] -= t;
                break;
            }
        }
    }
    return ans;
}

int main(){
    scanf("%d%d%d",&n,&m,&k);
    for (int x = 1; x<n; x++){
        int t;
        scanf("%d",&t);
        t--;
        adjl[t].push_back(x);
    }
    for (int x = 0; x<m; x++){
        int a,b;
        long long c;
        scanf("%d%d%lld",&a,&b,&c);
        a--;
        fruit[a] = true;
        day[a] = b;
        val[a] = c;
    }
    auto res = func(0);
    long long ans = 0;
    for (auto x : res){
        ans += x.second;
    }
    printf("%lld",ans);
}

Compilation message

magictree.cpp: In function 'std::map<int, int> func(int)':
magictree.cpp:15:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int x = 1; x<adjl[node].size(); x++){
                     ~^~~~~~~~~~~~~~~~~~
magictree.cpp: In function 'int main()':
magictree.cpp:44: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:47:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&t);
         ~~~~~^~~~~~~~~
magictree.cpp:54: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);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 6 ms 2688 KB Output is correct
5 Correct 6 ms 2688 KB Output is correct
6 Correct 7 ms 2688 KB Output is correct
7 Correct 7 ms 2688 KB Output is correct
8 Correct 6 ms 2688 KB Output is correct
9 Correct 7 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 82 ms 7520 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 2944 KB Output is correct
2 Correct 6 ms 2944 KB Output is correct
3 Correct 7 ms 2944 KB Output is correct
4 Correct 75 ms 25848 KB Output is correct
5 Correct 99 ms 28792 KB Output is correct
6 Correct 87 ms 25848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 88 ms 7288 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 6 ms 2688 KB Output is correct
5 Correct 6 ms 2688 KB Output is correct
6 Correct 7 ms 2688 KB Output is correct
7 Correct 7 ms 2688 KB Output is correct
8 Correct 6 ms 2688 KB Output is correct
9 Correct 7 ms 2688 KB Output is correct
10 Correct 92 ms 6688 KB Output is correct
11 Correct 95 ms 6624 KB Output is correct
12 Correct 79 ms 14456 KB Output is correct
13 Correct 60 ms 5228 KB Output is correct
14 Correct 68 ms 25464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 3328 KB Output is correct
2 Correct 36 ms 5760 KB Output is correct
3 Correct 42 ms 5688 KB Output is correct
4 Correct 40 ms 5732 KB Output is correct
5 Correct 19 ms 4344 KB Output is correct
6 Correct 43 ms 8952 KB Output is correct
7 Correct 46 ms 13568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 6 ms 2688 KB Output is correct
5 Correct 6 ms 2688 KB Output is correct
6 Correct 7 ms 2688 KB Output is correct
7 Correct 7 ms 2688 KB Output is correct
8 Correct 6 ms 2688 KB Output is correct
9 Correct 7 ms 2688 KB Output is correct
10 Correct 7 ms 2944 KB Output is correct
11 Correct 6 ms 2944 KB Output is correct
12 Correct 7 ms 2944 KB Output is correct
13 Correct 75 ms 25848 KB Output is correct
14 Correct 99 ms 28792 KB Output is correct
15 Correct 87 ms 25848 KB Output is correct
16 Correct 92 ms 6688 KB Output is correct
17 Correct 95 ms 6624 KB Output is correct
18 Correct 79 ms 14456 KB Output is correct
19 Correct 60 ms 5228 KB Output is correct
20 Correct 68 ms 25464 KB Output is correct
21 Correct 26 ms 3712 KB Output is correct
22 Correct 88 ms 6648 KB Output is correct
23 Correct 105 ms 8080 KB Output is correct
24 Correct 130 ms 9464 KB Output is correct
25 Correct 91 ms 8176 KB Output is correct
26 Correct 117 ms 13048 KB Output is correct
27 Correct 107 ms 15864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 6 ms 2688 KB Output is correct
5 Correct 6 ms 2688 KB Output is correct
6 Correct 7 ms 2688 KB Output is correct
7 Correct 7 ms 2688 KB Output is correct
8 Correct 6 ms 2688 KB Output is correct
9 Correct 7 ms 2688 KB Output is correct
10 Incorrect 82 ms 7520 KB Output isn't correct
11 Halted 0 ms 0 KB -