# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
579389 | juggernaut | Magic Tree (CEOI19_magictree) | C++14 | 432 ms | 6588 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 depth[100005];
int d[100005];
int w[100005];
int a[100005];
bool cmp(int l,int r){
if(d[l]==d[r])return depth[l]>depth[r];
return d[l]<d[r];
}
int timer;
int tin[100005];
int tout[100005];
int n,m,k;
void dfs(int v){
tin[v]=++timer;
for(int to:g[v]){
depth[to]=depth[v]+1;
dfs(to);
}
tout[v]=++timer;
}
bool upper(int a,int b){
return tin[a]<=tin[b]&&tout[a]>=tout[b];
}
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]);
}
dfs(1);
iota(a+1,a+1+n,1);
sort(a+1,a+1+n,cmp);
ll ans=0;
if(n>20)return 1;
for(int mask=0;mask<(1<<n);mask++){
bool flag=true;
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if((mask>>i&1)&&(mask>>j&1)&&(upper(a[i+1],a[j+1])))flag=false;
if(flag){
ll cnt=0;
for(int i=0;i<n;i++)if(mask>>i&1)cnt+=w[a[i+1]];
umax(ans,cnt);
}
}
cout<<ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |