Submission #242293

#TimeUsernameProblemLanguageResultExecution timeMemory
242293jamielimMagic Tree (CEOI19_magictree)C++14
37 / 100
130 ms35064 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> ii; typedef long double ld; #define mp make_pair #define pb push_back #define fi first #define se second #define ALL(x) x.begin(),x.end() #define SZ(x) (int)x.size() const int INF=2012345678; const ll LLINF=4012345678012345678LL; const ll MOD=1000000007; //998244353; // const ld PI=3.1415926535898; const ld EPS=1e-9; ll gcd(ll a,ll b){if(a<b)swap(a,b);if(b==0)return a;return gcd(b,a%b);} inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;} inline ll expo(ll b,ll p,ll m){ll res=1; while(p){if(p&1)res=(res*b)%m; b=(b*b)%m; p>>=1;} return res;} inline ll modinv(ll a,ll m){return expo(a,m-2,m);} int n,m,k; vector<int> adj[100005]; ii r[100005]; ll memo[100005][25]; void dfs(int x){ for(int i=0;i<SZ(adj[x]);i++){ dfs(adj[x][i]); for(int j=0;j<25;j++){ memo[x][j]+=memo[adj[x][i]][j]; } } memo[x][r[x].fi]+=r[x].se; for(int i=1;i<25;i++){ memo[x][i]=max(memo[x][i-1],memo[x][i]); } } int main(){ scanf("%d%d%d",&n,&m,&k); int p,v,d,w; for(int i=1;i<n;i++){ scanf("%d",&p);p--; adj[p].pb(i); } for(int i=0;i<n;i++)r[i]=mp(0LL,0LL); bool st2=1; for(int i=0;i<m;i++){ scanf("%d%d%d",&v,&d,&w);v--; r[v]=mp(d,w); if(SZ(adj[v])!=0)st2=0; } if(st2){ ll ans=0; for(int i=0;i<n;i++)ans+=r[i].se; printf("%lld",ans); }else{ dfs(0); printf("%lld",memo[0][k]); } }

Compilation message (stderr)

magictree.cpp: In function 'int main()':
magictree.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d",&n,&m,&k);
  ~~~~~^~~~~~~~~~~~~~~~~~~
magictree.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&p);p--;
   ~~~~~^~~~~~~~~
magictree.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d",&v,&d,&w);v--;
   ~~~~~^~~~~~~~~~~~~~~~~~~
#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...