Submission #579388

# Submission time Handle Problem Language Result Execution time Memory
579388 2022-06-19T04:21:24 Z temporary_juggernaut Magic Tree (CEOI19_magictree) C++14
6 / 100
2000 ms 8064 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;
}
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;
	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

magictree.cpp: In function 'int main()':
magictree.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |  scanf("%d%d%d",&n,&m,&k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
magictree.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   scanf("%d",&x);
      |   ~~~~~^~~~~~~~~
magictree.cpp:53:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |   scanf("%d",&v);
      |   ~~~~~^~~~~~~~~
magictree.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |   scanf("%d%d",&d[v],&w[v]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 379 ms 2664 KB Output is correct
3 Correct 403 ms 2664 KB Output is correct
4 Correct 380 ms 2672 KB Output is correct
5 Correct 354 ms 2656 KB Output is correct
6 Correct 388 ms 2660 KB Output is correct
7 Correct 401 ms 2660 KB Output is correct
8 Correct 435 ms 2660 KB Output is correct
9 Correct 378 ms 2656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2077 ms 6348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 108 ms 2772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2072 ms 6584 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 379 ms 2664 KB Output is correct
3 Correct 403 ms 2664 KB Output is correct
4 Correct 380 ms 2672 KB Output is correct
5 Correct 354 ms 2656 KB Output is correct
6 Correct 388 ms 2660 KB Output is correct
7 Correct 401 ms 2660 KB Output is correct
8 Correct 435 ms 2660 KB Output is correct
9 Correct 378 ms 2656 KB Output is correct
10 Execution timed out 2068 ms 8064 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 150 ms 3448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 379 ms 2664 KB Output is correct
3 Correct 403 ms 2664 KB Output is correct
4 Correct 380 ms 2672 KB Output is correct
5 Correct 354 ms 2656 KB Output is correct
6 Correct 388 ms 2660 KB Output is correct
7 Correct 401 ms 2660 KB Output is correct
8 Correct 435 ms 2660 KB Output is correct
9 Correct 378 ms 2656 KB Output is correct
10 Incorrect 108 ms 2772 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 379 ms 2664 KB Output is correct
3 Correct 403 ms 2664 KB Output is correct
4 Correct 380 ms 2672 KB Output is correct
5 Correct 354 ms 2656 KB Output is correct
6 Correct 388 ms 2660 KB Output is correct
7 Correct 401 ms 2660 KB Output is correct
8 Correct 435 ms 2660 KB Output is correct
9 Correct 378 ms 2656 KB Output is correct
10 Execution timed out 2077 ms 6348 KB Time limit exceeded
11 Halted 0 ms 0 KB -