Submission #896244

#TimeUsernameProblemLanguageResultExecution timeMemory
8962448pete8Magic Tree (CEOI19_magictree)C++17
58 / 100
143 ms157268 KiB
#include<iostream> #include<stack> #include<map> #include<vector> #include<string> #include<unordered_map> #include <queue> #include<cstring> #include<float.h> #include<limits.h> #include <cassert> #include<cmath> #include<set> #include<algorithm> #include <iomanip> #include<numeric> //gcd(a,b) #include<bitset> using namespace std; #define ll long long #define f first #define endl "\n" #define s second #define pii pair<int,int> #define ppii pair<int,pii> #define vi vector<int> #define pb push_back #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define F(n) for(int i=0;i<n;i++) #define lb lower_bound #define ub upper_bound #define fastio ios::sync_with_stdio(false);cin.tie(NULL); #pragma GCC optimize ("03,unroll-loops") using namespace std; //#define int long long #define double long double const int mod=998244353,mxn=1e6,lg=22;//inf=1e18,minf=-1e18,Mxn=100000; vector<int>adj[mxn+10]; ll dp[mxn+10][22]; map<int,ll>mp[mxn+10]; pair<int,ll> info[mxn+10]; int n,m,k; ll ans=0; void dfs2(int cur,int p){ for(auto i:adj[cur])dfs2(i,cur); for(auto i:adj[cur]){ if(mp[i].size()>mp[cur].size())swap(mp[cur],mp[i]); for(auto j:mp[i])mp[cur][j.f]+=j.s; } mp[cur][info[cur].f]+=info[cur].s; auto it=mp[cur].upper_bound(info[cur].f); while(it!=mp[cur].end()&&info[cur].s>0){ if(it==mp[cur].end())assert(0); if(info[cur].s>=it->s)info[cur].s-=it->s,mp[cur].erase(it); else {it->s-=info[cur].s;break;} } } int32_t main(){ fastio cin>>n>>m>>k; for(int i=2;i<=n;i++){ int p;cin>>p; adj[p].pb(i); } bool yes=true; for(int i=0;i<m;i++){ int v,d,w;cin>>v>>d>>w; info[v]={d,w}; } ans=0; dfs2(1,-1); for(auto i:mp[1])ans+=i.s; cout<<ans; return 0; }

Compilation message (stderr)

magictree.cpp: In function 'int32_t main()':
magictree.cpp:65:7: warning: unused variable 'yes' [-Wunused-variable]
   65 |  bool yes=true;
      |       ^~~
#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...