| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 490793 | ntabc05101 | 바이오칩 (IZhO12_biochips) | C++14 | 340 ms | 406452 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define taskname ""
const int inf = 1e9;
const int mxN = 200001;
const int mxM = 501;
int n, m;
int a[mxN], prv[mxN];
vector<int> adj[mxN];
int dp[mxN][mxM];
vector<int> lst;
void dfs(int u, int p = -1) {
	prv[u] = lst.size();
	for (auto &to: adj[u]) {
		if (to != p) {
			dfs(to, u);
		}
	}
	lst.push_back(u);
}
int main() {
	if (fopen(taskname".inp", "r")) {
		freopen(taskname".inp", "r", stdin);
		freopen(taskname".out", "w", stdout);
	}
	else {
		if (fopen(taskname".in", "r")) {
			freopen(taskname".in", "r", stdin);
			freopen(taskname".out", "w", stdout);
		}
	}
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m;
	int root = -1;
	for (int i = 0, x, y; i < n; i++) {
		cin >> x >> y; x--;
		a[i] = y;
		if (!(~x)) {
			root = i; continue;
		}
		adj[x].push_back(i);
		adj[i].push_back(x);
	}
	dfs(root);
	for (int j = 1; j <= m; j++) {
		dp[0][j] = -inf;
	}
	for (int i = 1; i <= lst.size(); i++) {
		auto &u = lst[i - 1];
		//cout << u << " " << prv[u] << "\n";
		for (int j = 1; j <= m; j++) {
			dp[i][j] = max(dp[i - 1][j], dp[prv[u]][j - 1] + a[u]);
		}
	}
	cout << dp[lst.size()][m] << "\n";
	return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
