# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
579413 | 2022-06-19T05:37:48 Z | temporary_juggernaut | Amusement Park (CEOI19_amusementpark) | C++14 | 6 ms | 7352 KB |
#include<bits/stdc++.h> #define fr first #define sc second using namespace std; typedef long long ll; typedef long double ld; #define USING_ORDERED_SET 0 #if USING_ORDERED_SET #include<bits/extc++.h> using namespace __gnu_pbds; template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; #endif template<class T>void umax(T &a,T b){if(a<b)a=b;} template<class T>void umin(T &a,T b){if(b<a)a=b;} #ifdef juggernaut #define printl(args...) printf(args) #else #define printl(args...) 0 #endif vector<int>g[100005]; int d[100005]; int w[100005]; int n,m,k; map<int,ll>mp[100005]; int id[100005]; void dfs(int v){ int mx=0; for(int to:g[v]){ dfs(to); if(!mx||mp[id[to]].size()>mp[id[mx]].size())mx=to; } if(!mx){ id[v]=v; mp[v][d[v]]+=w[v]; return; } id[v]=id[mx]; for(int to:g[v])if(to^mx)for(auto tmp:mp[id[to]])mp[id[v]][tmp.fr]+=tmp.sc; mp[id[v]][d[v]]+=w[v]; auto x=mp[id[v]].upper_bound(d[v]); x->sc-=w[v]; while(x!=mp[id[v]].end()){ auto y=x; y++; if(x->sc>=0)break; if(y!=mp[id[v]].end())y->sc+=x->sc; mp[id[v]].erase(x->fr); x=y; } } int main(){ scanf("%d%d%d",&n,&m,&k); for(int i=2;i<=n;i++){ int x; scanf("%d",&x); g[x].push_back(i); } while(m--){ int v; scanf("%d",&v); scanf("%d%d",&d[v],&w[v]); } ll ans=0; dfs(1); for(auto to:mp[id[1]])ans+=to.sc; cout<<ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 7252 KB | Output is correct |
2 | Incorrect | 6 ms | 7352 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 7252 KB | Output is correct |
2 | Incorrect | 6 ms | 7352 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 7252 KB | Output is correct |
2 | Incorrect | 6 ms | 7352 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 7252 KB | Output is correct |
2 | Incorrect | 6 ms | 7352 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 7252 KB | Output is correct |
2 | Incorrect | 6 ms | 7352 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |