Submission #249252

# Submission time Handle Problem Language Result Execution time Memory
249252 2020-07-14T14:15:23 Z sahil_k Fireworks (APIO16_fireworks) C++14
19 / 100
20 ms 1024 KB
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int n, m;
vector< pair<int, int> > adj[310];
long long dp[310][310];
void dfs (int x) {
	if (adj[x].size() == 0) {
		dp[x][0] = 0;
		for (int i=1; i<=300; i++) {
			dp[x][i] = 1e16;
		}
		return;
	}
	for (auto i: adj[x]) {
		dfs(i.first);
	}
	for (int i=0; i<=300; i++) {
		for (auto j: adj[x]) {
			long long best = 1e16;
			for (int k=0; k<=i; k++) {
				best = min(best, dp[j.first][k]+abs(i-k-j.second));
			}
			dp[x][i] += best;
		}
	}
}
int main () {
	cin >> n >> m;
	int pi, wi;
	for (int i=2; i<=n+m; i++) {
		cin >> pi >> wi;
		adj[pi].push_back({i, wi});
	}
	dfs(1);
	long long o = 1e16;
	for (int i=0; i<=300; i++) {
		o = min(o, dp[1][i]);
	}
	cout << o << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 8 ms 640 KB Output is correct
6 Correct 8 ms 640 KB Output is correct
7 Correct 10 ms 768 KB Output is correct
8 Correct 11 ms 768 KB Output is correct
9 Correct 12 ms 768 KB Output is correct
10 Correct 13 ms 896 KB Output is correct
11 Correct 15 ms 896 KB Output is correct
12 Correct 16 ms 896 KB Output is correct
13 Correct 17 ms 1024 KB Output is correct
14 Correct 19 ms 1016 KB Output is correct
15 Correct 19 ms 1024 KB Output is correct
16 Correct 19 ms 1024 KB Output is correct
17 Correct 19 ms 1024 KB Output is correct
18 Correct 19 ms 1024 KB Output is correct
19 Correct 20 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -