Submission #579383

# Submission time Handle Problem Language Result Execution time Memory
579383 2022-06-19T03:58:34 Z temporary_juggernaut Amusement Park (CEOI19_amusementpark) C++14
0 / 100
2 ms 2644 KB
#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;
}
ll tree[400005];
/*void update(int v,int l,int r,int pos,ll val){
	if(l==r){
		tree[v]=pos;
		return;
	}
	int mid=(l+r)>>1;
	if(pos<=mid)update(v<<1,l,mid,pos,val);
	else update(v<<1|1,mid+1,r,pos,val);
	tree[v]=max(tree[v<<1],tree[v<<1|1]);
}
ll get(int v,int l,int r,int ql,int qr){
	if(qr<l||r<ql)return 0ll;
	if(ql<=l&&r<=qr)return tree[v];
	int mid=(l+r)>>1;
	return max(get(v<<1,l,mid,ql,qr),get(v<<1|1,mid+1,r,ql,qr));
}
ll query(int l,int r){
	if(l>r)return 0ll;
	return get(1,1,n,l,r);
}*/
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;
	for(int i=n;i;i--){
		int &v=a[i];
		//update(1,1,n,tin[v],max(query(1,tin[v]-1),query(tout[v]+1,n))+w[v]);
		for(int j=1;j<=n;j++)if(!(tin[v]<=tin[j]&&tout[v]>=tout[j]))umax(tree[v],tree[j]);
		tree[v]+=w[v];
		umax(ans,tree[v]);
	}
	cout<<ans;
}

Compilation message

amusementpark.cpp: In function 'int main()':
amusementpark.cpp:63:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |  scanf("%d%d%d",&n,&m,&k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
amusementpark.cpp:66:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |   scanf("%d",&x);
      |   ~~~~~^~~~~~~~~
amusementpark.cpp:71:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |   scanf("%d",&v);
      |   ~~~~~^~~~~~~~~
amusementpark.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |   scanf("%d%d",&d[v],&w[v]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Incorrect 2 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Incorrect 2 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Incorrect 2 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Incorrect 2 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Incorrect 2 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -