Submission #898753

# Submission time Handle Problem Language Result Execution time Memory
898753 2024-01-05T05:27:00 Z vjudge1 Magic Tree (CEOI19_magictree) C++17
6 / 100
1344 ms 84272 KB
#include <bits/stdc++.h>
using namespace std;
const int mxn=21;
int n,m,k,dp[mxn][1<<20],par[mxn],fru[mxn][mxn],sz;
vector<int>v[mxn];
void dfs(int z,int j){
	for(auto i:v[z]){
		if(!(j&(1<<i-1)))
			dfs(i,j);
	}
	sz++;
}
int main(){
	cin>>n>>m>>k;
	for(int i=2;i<=n;i++){
		cin>>par[i];
		v[par[i]].push_back(i);
	}
	for(int i=1;i<=m;i++){
		int d,x,y;
		cin>>x>>d>>y;
		fru[x][d]=y;
	}
	for(int i=1;i<=k;i++){
		for(int j=1;j<(1<<n);j++){
			sz=0;
			dfs(1,j);
			if(sz==n-__builtin_popcount(j)){//cout<<j<<" ";
				dp[i][j]=dp[i-1][j];
				for(int w=1;w<=n;w++){
					if((j&(1<<w)) && !(j&(1<<par[w+1]-1))){
						dp[i][j]=max(dp[i][j],dp[i][j-(1<<w)]+fru[w+1][i]);
					}
				}
			}
			}
	}
	int ans=0;
	for(int j=1;j<(1<<n);j++){
		ans=max(ans,dp[k][j]);
	}
	cout<<ans<<endl;
}

Compilation message

magictree.cpp: In function 'void dfs(int, int)':
magictree.cpp:8:15: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
    8 |   if(!(j&(1<<i-1)))
      |              ~^~
magictree.cpp: In function 'int main()':
magictree.cpp:31:39: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   31 |      if((j&(1<<w)) && !(j&(1<<par[w+1]-1))){
      |                               ~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 20828 KB Output is correct
2 Correct 821 ms 84272 KB Output is correct
3 Correct 323 ms 43464 KB Output is correct
4 Correct 164 ms 35152 KB Output is correct
5 Correct 171 ms 80412 KB Output is correct
6 Correct 147 ms 80636 KB Output is correct
7 Correct 149 ms 80444 KB Output is correct
8 Correct 1344 ms 84148 KB Output is correct
9 Correct 202 ms 83272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 20828 KB Output is correct
2 Correct 821 ms 84272 KB Output is correct
3 Correct 323 ms 43464 KB Output is correct
4 Correct 164 ms 35152 KB Output is correct
5 Correct 171 ms 80412 KB Output is correct
6 Correct 147 ms 80636 KB Output is correct
7 Correct 149 ms 80444 KB Output is correct
8 Correct 1344 ms 84148 KB Output is correct
9 Correct 202 ms 83272 KB Output is correct
10 Runtime error 2 ms 348 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 20828 KB Output is correct
2 Correct 821 ms 84272 KB Output is correct
3 Correct 323 ms 43464 KB Output is correct
4 Correct 164 ms 35152 KB Output is correct
5 Correct 171 ms 80412 KB Output is correct
6 Correct 147 ms 80636 KB Output is correct
7 Correct 149 ms 80444 KB Output is correct
8 Correct 1344 ms 84148 KB Output is correct
9 Correct 202 ms 83272 KB Output is correct
10 Runtime error 2 ms 348 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 20828 KB Output is correct
2 Correct 821 ms 84272 KB Output is correct
3 Correct 323 ms 43464 KB Output is correct
4 Correct 164 ms 35152 KB Output is correct
5 Correct 171 ms 80412 KB Output is correct
6 Correct 147 ms 80636 KB Output is correct
7 Correct 149 ms 80444 KB Output is correct
8 Correct 1344 ms 84148 KB Output is correct
9 Correct 202 ms 83272 KB Output is correct
10 Runtime error 2 ms 348 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -