답안 #1118369

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1118369 2024-11-25T12:05:03 Z alexdd Magic Tree (CEOI19_magictree) C++17
100 / 100
140 ms 35924 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];
void dfs(int nod)
{
    int maxc=-1,heavy=-1;
    for(int adj:con[nod])
    {
        dfs(adj);
        if((int)dp[adj].size() > maxc)
            maxc = dp[adj].size(), heavy = adj;
    }
    if(heavy!=-1) 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;
            }
        }
    }
}
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 3 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 9820 KB Output is correct
5 Correct 2 ms 9820 KB Output is correct
6 Correct 2 ms 8032 KB Output is correct
7 Correct 3 ms 8028 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Correct 3 ms 8028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 19020 KB Output is correct
2 Correct 38 ms 19800 KB Output is correct
3 Correct 134 ms 35216 KB Output is correct
4 Correct 65 ms 19964 KB Output is correct
5 Correct 112 ms 21844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9820 KB Output is correct
2 Correct 3 ms 9820 KB Output is correct
3 Correct 3 ms 10060 KB Output is correct
4 Correct 61 ms 27000 KB Output is correct
5 Correct 71 ms 30804 KB Output is correct
6 Correct 63 ms 26964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 15180 KB Output is correct
2 Correct 55 ms 14528 KB Output is correct
3 Correct 42 ms 18952 KB Output is correct
4 Correct 32 ms 16152 KB Output is correct
5 Correct 45 ms 26868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 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 9820 KB Output is correct
5 Correct 2 ms 9820 KB Output is correct
6 Correct 2 ms 8032 KB Output is correct
7 Correct 3 ms 8028 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Correct 3 ms 8028 KB Output is correct
10 Correct 66 ms 19272 KB Output is correct
11 Correct 56 ms 17992 KB Output is correct
12 Correct 40 ms 19016 KB Output is correct
13 Correct 31 ms 16076 KB Output is correct
14 Correct 49 ms 26952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9040 KB Output is correct
2 Correct 33 ms 11856 KB Output is correct
3 Correct 28 ms 11872 KB Output is correct
4 Correct 26 ms 11764 KB Output is correct
5 Correct 13 ms 10712 KB Output is correct
6 Correct 29 ms 14420 KB Output is correct
7 Correct 27 ms 18016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 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 9820 KB Output is correct
5 Correct 2 ms 9820 KB Output is correct
6 Correct 2 ms 8032 KB Output is correct
7 Correct 3 ms 8028 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Correct 3 ms 8028 KB Output is correct
10 Correct 3 ms 9820 KB Output is correct
11 Correct 3 ms 9820 KB Output is correct
12 Correct 3 ms 10060 KB Output is correct
13 Correct 61 ms 27000 KB Output is correct
14 Correct 71 ms 30804 KB Output is correct
15 Correct 63 ms 26964 KB Output is correct
16 Correct 66 ms 19272 KB Output is correct
17 Correct 56 ms 17992 KB Output is correct
18 Correct 40 ms 19016 KB Output is correct
19 Correct 31 ms 16076 KB Output is correct
20 Correct 49 ms 26952 KB Output is correct
21 Correct 21 ms 12160 KB Output is correct
22 Correct 63 ms 20924 KB Output is correct
23 Correct 72 ms 25172 KB Output is correct
24 Correct 140 ms 35924 KB Output is correct
25 Correct 53 ms 19836 KB Output is correct
26 Correct 91 ms 22552 KB Output is correct
27 Correct 74 ms 21332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 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 9820 KB Output is correct
5 Correct 2 ms 9820 KB Output is correct
6 Correct 2 ms 8032 KB Output is correct
7 Correct 3 ms 8028 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Correct 3 ms 8028 KB Output is correct
10 Correct 43 ms 19020 KB Output is correct
11 Correct 38 ms 19800 KB Output is correct
12 Correct 134 ms 35216 KB Output is correct
13 Correct 65 ms 19964 KB Output is correct
14 Correct 112 ms 21844 KB Output is correct
15 Correct 3 ms 9820 KB Output is correct
16 Correct 3 ms 9820 KB Output is correct
17 Correct 3 ms 10060 KB Output is correct
18 Correct 61 ms 27000 KB Output is correct
19 Correct 71 ms 30804 KB Output is correct
20 Correct 63 ms 26964 KB Output is correct
21 Correct 73 ms 15180 KB Output is correct
22 Correct 55 ms 14528 KB Output is correct
23 Correct 42 ms 18952 KB Output is correct
24 Correct 32 ms 16152 KB Output is correct
25 Correct 45 ms 26868 KB Output is correct
26 Correct 66 ms 19272 KB Output is correct
27 Correct 56 ms 17992 KB Output is correct
28 Correct 40 ms 19016 KB Output is correct
29 Correct 31 ms 16076 KB Output is correct
30 Correct 49 ms 26952 KB Output is correct
31 Correct 11 ms 9040 KB Output is correct
32 Correct 33 ms 11856 KB Output is correct
33 Correct 28 ms 11872 KB Output is correct
34 Correct 26 ms 11764 KB Output is correct
35 Correct 13 ms 10712 KB Output is correct
36 Correct 29 ms 14420 KB Output is correct
37 Correct 27 ms 18016 KB Output is correct
38 Correct 21 ms 12160 KB Output is correct
39 Correct 63 ms 20924 KB Output is correct
40 Correct 72 ms 25172 KB Output is correct
41 Correct 140 ms 35924 KB Output is correct
42 Correct 53 ms 19836 KB Output is correct
43 Correct 91 ms 22552 KB Output is correct
44 Correct 74 ms 21332 KB Output is correct
45 Correct 20 ms 11612 KB Output is correct
46 Correct 70 ms 20060 KB Output is correct
47 Correct 67 ms 23336 KB Output is correct
48 Correct 111 ms 32460 KB Output is correct
49 Correct 58 ms 19836 KB Output is correct
50 Correct 116 ms 21860 KB Output is correct
51 Correct 87 ms 20924 KB Output is correct