Submission #242286

# Submission time Handle Problem Language Result Execution time Memory
242286 2020-06-27T08:14:35 Z jamielim Magic Tree (CEOI19_magictree) C++14
3 / 100
160 ms 45048 KB
#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][2];

ll dfs(int x,int t,int f){
	if(memo[x][t][f]!=-1)return memo[x][t][f];
	if(f){
		ll ans=(r[x].fi<=t?r[x].se:0);
		for(int i=0;i<SZ(adj[x]);i++){
			ans+=max(dfs(adj[x][i],r[x].fi,0),dfs(adj[x][i],r[x].fi,1));
		}
		//printf("%d %d %d %lld\n",x,t,f,ans);
		return memo[x][t][f]=ans;
	}else{
		ll ans=0;
		for(int i=0;i<SZ(adj[x]);i++){
			ans+=max(dfs(adj[x][i],t,0),dfs(adj[x][i],t,1));
		}
		//printf("%d %d %d %lld\n",x,t,f,ans);
		return memo[x][t][f]=ans;
	}
}

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{
		memset(memo,-1,sizeof(memo));
		printf("%lld",max(dfs(0,k,0),dfs(0,k,1)));
	}
}

Compilation message

magictree.cpp: In function 'int main()':
magictree.cpp:48: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:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&p);p--;
   ~~~~~^~~~~~~~~
magictree.cpp:57: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 time Memory Grader output
1 Correct 27 ms 41856 KB Output is correct
2 Correct 29 ms 41856 KB Output is correct
3 Correct 26 ms 41856 KB Output is correct
4 Correct 29 ms 41856 KB Output is correct
5 Incorrect 29 ms 41848 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 49 ms 5624 KB Output is correct
2 Correct 37 ms 6784 KB Output is correct
3 Correct 68 ms 4984 KB Output is correct
4 Correct 61 ms 4728 KB Output is correct
5 Correct 61 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 41984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 160 ms 45048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 41856 KB Output is correct
2 Correct 29 ms 41856 KB Output is correct
3 Correct 26 ms 41856 KB Output is correct
4 Correct 29 ms 41856 KB Output is correct
5 Incorrect 29 ms 41848 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 42488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 41856 KB Output is correct
2 Correct 29 ms 41856 KB Output is correct
3 Correct 26 ms 41856 KB Output is correct
4 Correct 29 ms 41856 KB Output is correct
5 Incorrect 29 ms 41848 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 41856 KB Output is correct
2 Correct 29 ms 41856 KB Output is correct
3 Correct 26 ms 41856 KB Output is correct
4 Correct 29 ms 41856 KB Output is correct
5 Incorrect 29 ms 41848 KB Output isn't correct
6 Halted 0 ms 0 KB -