Submission #896231

#TimeUsernameProblemLanguageResultExecution timeMemory
8962318pete8Magic Tree (CEOI19_magictree)C++17
34 / 100
2055 ms36624 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=1e5,lg=22;//inf=1e18,minf=-1e18,Mxn=100000; vector<int>adj[mxn+10]; int dp[mxn+10][22],hvy[mxn+10],sz[mxn+10]; pii info[mxn+10]; vector<int>v[mxn+10]; int n,m,k; int ans=0; void init(int cur,int p){ sz[cur]=1; for(auto i:adj[cur]){ init(i,cur); sz[cur]+=sz[i]; } for(auto i:adj[cur])if(sz[hvy[cur]]<sz[i])hvy[cur]=i; } void dfs(int cur,int p){ for(auto i:adj[cur])dfs(i,cur); for(auto i:adj[cur])for(int j=0;j<=k;j++)dp[cur][j]+=dp[i][j]; dp[cur][info[cur].f]+=info[cur].s; for(int j=1;j<=k;j++)dp[cur][j]=max(dp[cur][j],dp[cur][j-1]); } void solve(int cur,int p){ for(auto i:adj[cur])solve(i,cur); if(hvy[cur])swap(v[cur],v[hvy[cur]]); for(auto i:adj[cur])if(i!=hvy[cur])for(auto j:v[i])v[cur].pb(j); sort(all(v[cur])); if(info[cur].s==0)return; auto it=upper_bound(all(v[cur]),info[cur].f); int pos=it-v[cur].begin(); if(it!=v[cur].end())(*it)=info[cur].f; else v[cur].pb(info[cur].f); } int32_t main(){ fastio cin>>n>>m>>k; for(int i=2;i<=n;i++){ int p;cin>>p; adj[p].pb(i); } for(int i=0;i<m;i++){ int v,d,w;cin>>v>>d>>w; info[v]={d,w}; } if(k<=20){//sub 1 4 5 dfs(1,-1); for(int i=0;i<=k;i++)ans=max(ans,dp[1][i]); cout<<ans; } else{ //sub w=1 init(1,-1); solve(1,-1); cout<<v[1].size(); } return 0; }

Compilation message (stderr)

magictree.cpp: In function 'void solve(long long int, long long int)':
magictree.cpp:65:6: warning: unused variable 'pos' [-Wunused-variable]
   65 |  int pos=it-v[cur].begin();
      |      ^~~
#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...