답안 #1118368

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1118368 2024-11-25T12:03:22 Z alexdd Magic Tree (CEOI19_magictree) C++17
100 / 100
136 ms 37720 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e9;
int n,m,k;
vector<int> con[100005];
int parent[100005];
int d[100005],w[100005];
map<int,int> dp[100005];///{poz,dif}
void dfs(int nod)
{
    int maxc=-1,heavy=-1;
    for(int adj:con[nod])
    {
        dfs(adj);
        ///for(int i=1;i<=k;i++)
           /// dp[nod][i] += dp[adj][i];
        if((int)dp[adj].size() > maxc)
            maxc = dp[adj].size(), heavy = adj;
    }
    ///dp[nod][d[nod]] += w[nod];
    ///for(int i=1;i<=k;i++) dp[nod][i] = max(dp[nod][i], dp[nod][i-1]);
    if(heavy==-1)
    {
        if(w[nod]) dp[nod][d[nod]] += w[nod];
    }
    else
    {
        swap(dp[nod], dp[heavy]);
        for(int adj:con[nod])
        {
            if(adj==heavy)
                continue;
            for(auto it:dp[adj])
            {
                dp[nod][it.first] += it.second;
            }
        }
        if(w[nod] > 0)
        {
            dp[nod][d[nod]] += w[nod];
            auto it = dp[nod].upper_bound(d[nod]);
            int cur = w[nod];
            while(it!=dp[nod].end())
            {
                if((*it).second < cur)
                {
                    cur -= (*it).second;
                    it = dp[nod].erase(it);
                }
                else
                {
                    pair<int,int> cop = *it;
                    dp[nod][cop.first] -= cur;
                    cur = 0;
                    break;
                }
            }
        }
    }
    /*cout<<nod<<":\n";
    for(auto it:s[nod])
        cout<<it.first.first<<" "<<it.first.second<<"   "<<it.second<<"\n";
    cout<<"\n\n\n";*/
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>m>>k;
    for(int i=2;i<=n;i++)
    {
        cin>>parent[i];
        con[parent[i]].push_back(i);
    }
    for(int i=1;i<=m;i++)
    {
        int x;
        cin>>x;
        cin>>d[x]>>w[x];
    }
    dfs(1);
    int sum=0,mxm=0;
    for(auto it:dp[1])
    {
        sum += it.second;
        mxm = max(mxm, sum);
    }
    cout<<mxm;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9820 KB Output is correct
2 Correct 3 ms 9820 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 3 ms 8028 KB Output is correct
5 Correct 3 ms 9820 KB Output is correct
6 Correct 3 ms 9820 KB Output is correct
7 Correct 3 ms 9820 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Correct 3 ms 9820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 20316 KB Output is correct
2 Correct 33 ms 21968 KB Output is correct
3 Correct 127 ms 37720 KB Output is correct
4 Correct 67 ms 21972 KB Output is correct
5 Correct 103 ms 24112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 3 ms 8288 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 46 ms 28792 KB Output is correct
5 Correct 66 ms 32856 KB Output is correct
6 Correct 72 ms 28892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 17496 KB Output is correct
2 Correct 64 ms 16644 KB Output is correct
3 Correct 43 ms 21248 KB Output is correct
4 Correct 36 ms 17868 KB Output is correct
5 Correct 41 ms 29000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9820 KB Output is correct
2 Correct 3 ms 9820 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 3 ms 8028 KB Output is correct
5 Correct 3 ms 9820 KB Output is correct
6 Correct 3 ms 9820 KB Output is correct
7 Correct 3 ms 9820 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Correct 3 ms 9820 KB Output is correct
10 Correct 61 ms 20604 KB Output is correct
11 Correct 56 ms 19304 KB Output is correct
12 Correct 37 ms 20552 KB Output is correct
13 Correct 38 ms 17348 KB Output is correct
14 Correct 53 ms 28488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10320 KB Output is correct
2 Correct 28 ms 12376 KB Output is correct
3 Correct 21 ms 12296 KB Output is correct
4 Correct 27 ms 12464 KB Output is correct
5 Correct 10 ms 11388 KB Output is correct
6 Correct 25 ms 14928 KB Output is correct
7 Correct 30 ms 18572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9820 KB Output is correct
2 Correct 3 ms 9820 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 3 ms 8028 KB Output is correct
5 Correct 3 ms 9820 KB Output is correct
6 Correct 3 ms 9820 KB Output is correct
7 Correct 3 ms 9820 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Correct 3 ms 9820 KB Output is correct
10 Correct 4 ms 9820 KB Output is correct
11 Correct 3 ms 8288 KB Output is correct
12 Correct 4 ms 9820 KB Output is correct
13 Correct 46 ms 28792 KB Output is correct
14 Correct 66 ms 32856 KB Output is correct
15 Correct 72 ms 28892 KB Output is correct
16 Correct 61 ms 20604 KB Output is correct
17 Correct 56 ms 19304 KB Output is correct
18 Correct 37 ms 20552 KB Output is correct
19 Correct 38 ms 17348 KB Output is correct
20 Correct 53 ms 28488 KB Output is correct
21 Correct 19 ms 12368 KB Output is correct
22 Correct 74 ms 21936 KB Output is correct
23 Correct 76 ms 26184 KB Output is correct
24 Correct 134 ms 37712 KB Output is correct
25 Correct 54 ms 21204 KB Output is correct
26 Correct 96 ms 24328 KB Output is correct
27 Correct 70 ms 23128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9820 KB Output is correct
2 Correct 3 ms 9820 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 3 ms 8028 KB Output is correct
5 Correct 3 ms 9820 KB Output is correct
6 Correct 3 ms 9820 KB Output is correct
7 Correct 3 ms 9820 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Correct 3 ms 9820 KB Output is correct
10 Correct 45 ms 20316 KB Output is correct
11 Correct 33 ms 21968 KB Output is correct
12 Correct 127 ms 37720 KB Output is correct
13 Correct 67 ms 21972 KB Output is correct
14 Correct 103 ms 24112 KB Output is correct
15 Correct 4 ms 9820 KB Output is correct
16 Correct 3 ms 8288 KB Output is correct
17 Correct 4 ms 9820 KB Output is correct
18 Correct 46 ms 28792 KB Output is correct
19 Correct 66 ms 32856 KB Output is correct
20 Correct 72 ms 28892 KB Output is correct
21 Correct 52 ms 17496 KB Output is correct
22 Correct 64 ms 16644 KB Output is correct
23 Correct 43 ms 21248 KB Output is correct
24 Correct 36 ms 17868 KB Output is correct
25 Correct 41 ms 29000 KB Output is correct
26 Correct 61 ms 20604 KB Output is correct
27 Correct 56 ms 19304 KB Output is correct
28 Correct 37 ms 20552 KB Output is correct
29 Correct 38 ms 17348 KB Output is correct
30 Correct 53 ms 28488 KB Output is correct
31 Correct 7 ms 10320 KB Output is correct
32 Correct 28 ms 12376 KB Output is correct
33 Correct 21 ms 12296 KB Output is correct
34 Correct 27 ms 12464 KB Output is correct
35 Correct 10 ms 11388 KB Output is correct
36 Correct 25 ms 14928 KB Output is correct
37 Correct 30 ms 18572 KB Output is correct
38 Correct 19 ms 12368 KB Output is correct
39 Correct 74 ms 21936 KB Output is correct
40 Correct 76 ms 26184 KB Output is correct
41 Correct 134 ms 37712 KB Output is correct
42 Correct 54 ms 21204 KB Output is correct
43 Correct 96 ms 24328 KB Output is correct
44 Correct 70 ms 23128 KB Output is correct
45 Correct 17 ms 13408 KB Output is correct
46 Correct 69 ms 21460 KB Output is correct
47 Correct 87 ms 24952 KB Output is correct
48 Correct 136 ms 34880 KB Output is correct
49 Correct 72 ms 21900 KB Output is correct
50 Correct 97 ms 24400 KB Output is correct
51 Correct 72 ms 23284 KB Output is correct