Submission #379368

#TimeUsernameProblemLanguageResultExecution timeMemory
379368YJUMagic Tree (CEOI19_magictree)C++14
100 / 100
225 ms39552 KiB
#include<bits/stdc++.h> #pragma GCC optimzie("unroll-loops,no-stack-ptorector,Ofast") using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pll; const ll N=1e5+5; const ll MOD=1e9+7; const ld pi=acos(-1); const ll INF=(1LL<<60); #define REP(i,n) for(int i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define pb push_back #define mp make_pair #define X first #define Y second #define lwb lower_bound #define ALL(_a) _a.begin(),_a.end() #define SZ(_a) (ll)_a.size() ll n,m,k,x,y,day[N],weight[N]; vector<ll> v[N]; ll dp[N]; map<ll,ll> mm[N]; ll mg(ll a,ll b){ if(SZ(mm[a])>SZ(mm[b]))swap(a,b); for(auto i:mm[a])mm[b][i.X]+=i.Y; return b; } void DFS(ll nd){ dp[nd]=nd; for(ll i:v[nd]){ DFS(i); //dp[nd]=mg(dp[nd],dp[i]); dp[nd]=mg(dp[nd],dp[i]); //REP(j,k+1)dp[nd][j]+=dp[i][j]; } ll last=weight[nd]; vector<ll> era; map<ll,ll> &DP=mm[dp[nd]]; if(DP.lwb(day[nd]+1)!=DP.end())for(int i=DP.lwb(day[nd]+1)->X;i<=k;i=DP.lwb(i+1)->X){ if(last==0)break; if(last>DP[i]){ last-=DP[i]; era.pb(i); }else{ DP[i]-=last; last=0; } if(DP.lwb(i+1)==DP.end())break; } for(ll i:era)DP.erase(i); DP[day[nd]]+=weight[nd]; //dp[nd][day[nd]]+=weight[nd]; //REP1(j,k)dp[nd][j]=max(dp[nd][j],dp[nd][j-1]); } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>m>>k; for(int i=2;i<=n;i++){ cin>>x;v[x].pb(i); } REP(i,m){ cin>>x>>y; day[x]=y; cin>>weight[x]; //for(int j=y+1;j<=k;j++)weight[x][j]=weight[x][y]; } DFS(1); /*REP1(i,n){ cout<<"Node::"<<i<<"\n"; REP(j,k+1){ cout<<setw(2)<<dp[i][j]<<" \n"[j==k]; } } */ ll ans=0; for(auto i:mm[dp[1]])ans+=i.Y; cout<<ans<<"\n"; return 0; }

Compilation message (stderr)

magictree.cpp:2: warning: ignoring #pragma GCC optimzie [-Wunknown-pragmas]
    2 | #pragma GCC optimzie("unroll-loops,no-stack-ptorector,Ofast")
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...