답안 #1115884

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1115884 2024-11-21T03:28:01 Z guagua0407 Magic Tree (CEOI19_magictree) C++17
16 / 100
129 ms 32584 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

const int mxn=1e5+5;
vector<int> adj[mxn];
set<pair<int,int>> S[mxn];
int d[mxn];
int w[mxn];

void dfs(int v,int p=0){
    for(auto u:adj[v]){
        dfs(u,v);
        if(S[v].size()<S[u].size()){
            swap(S[v],S[u]);
        }
        for(auto x:S[u]){
            S[v].insert(x);
        }
    }
    auto it=S[v].lower_bound({d[v]+1,0});
    int sum=0;
    while(it!=S[v].end() and sum+(*it).s<=w[v]){
        sum+=(*it).s;
        it=S[v].erase(it);
    }
    if(it!=S[v].end()){
        auto p=(*it);
        S[v].erase(it);
        p.s=sum+p.s-w[v];
        S[v].insert(p);
    }
    S[v].insert({d[v],w[v]});
    /*cout<<v<<'\n';
    for(auto x:S[v]){
        cout<<x.f<<' '<<x.s<<'\n';
    }*/
}

int main() {_
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=2;i<=n;i++){
        int p;
        cin>>p;
        adj[p].push_back(i);
    }
    for(int i=0;i<m;i++){
        int v;
        cin>>v;
        cin>>d[v]>>w[v];
    }
    dfs(1);
    ll ans=0;
    for(auto v:S[1]){
        ans+=v.s;
    }
    cout<<ans<<'\n';
    return 0;
}
//maybe its multiset not set
//yeeorz
//diaoborz

Compilation message

magictree.cpp: In function 'void setIO(std::string)':
magictree.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 8016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 18724 KB Output is correct
2 Correct 47 ms 18248 KB Output is correct
3 Correct 129 ms 32584 KB Output is correct
4 Correct 69 ms 19508 KB Output is correct
5 Correct 93 ms 20824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 8016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 115 ms 30288 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 8016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 9116 KB Output is correct
2 Correct 31 ms 12872 KB Output is correct
3 Correct 23 ms 12724 KB Output is correct
4 Correct 32 ms 12872 KB Output is correct
5 Correct 14 ms 13520 KB Output is correct
6 Correct 26 ms 15184 KB Output is correct
7 Correct 24 ms 16656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 8016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 8016 KB Output isn't correct
2 Halted 0 ms 0 KB -