Submission #913950

# Submission time Handle Problem Language Result Execution time Memory
913950 2024-01-20T16:07:45 Z daoquanglinh2007 Biochips (IZhO12_biochips) C++17
0 / 100
4 ms 6744 KB
#include <bits/stdc++.h>
using namespace std;

const int NM = 2e5, MM = 500, inf = 1e9;

int N, M, root, p[NM+5], x[NM+5], timer = 0, tin[NM+5], tout[NM+5], tour[NM+5];
vector <int> son[NM+5];
int dp[NM+5][MM+5];

void dfs_euler_tour(int u){
	tin[u] = ++timer;
	tour[timer] = u;
	for (int v : son[u]){
		dfs_euler_tour(v);
	}
	tout[u] = timer;
}

int main(){
	freopen("BIOCHIPS.inp", "r", stdin);
	freopen("BIOCHIPS.out", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> N >> M;
	for (int i = 1; i <= N; i++){
		cin >> p[i] >> x[i];
		if (p[i] == 0) root = i;
		son[p[i]].push_back(i);
	}
	dfs_euler_tour(root);
	for (int i = 1; i <= M; i++) dp[N+1][i] = -inf;
	for (int i = N; i >= 1; i--){
		int u = tour[i];
		for (int j = 1; j <= M; j++)
			dp[i][j] = max(dp[tout[u]][j-1]+x[u], dp[i+1][j]);
	}
	cout << dp[1][M];
	return 0;
}

Compilation message

biochips.cpp: In function 'int main()':
biochips.cpp:20:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |  freopen("BIOCHIPS.inp", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
biochips.cpp:21:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |  freopen("BIOCHIPS.out", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 6492 KB Output isn't correct
2 Incorrect 3 ms 6492 KB Output isn't correct
3 Incorrect 3 ms 6488 KB Output isn't correct
4 Incorrect 3 ms 6488 KB Output isn't correct
5 Incorrect 3 ms 6492 KB Output isn't correct
6 Incorrect 4 ms 6492 KB Output isn't correct
7 Incorrect 3 ms 6492 KB Output isn't correct
8 Incorrect 3 ms 6744 KB Output isn't correct
9 Incorrect 3 ms 6492 KB Output isn't correct
10 Incorrect 3 ms 6492 KB Output isn't correct