답안 #725219

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
725219 2023-04-17T03:52:04 Z pavement Magic Tree (CEOI19_magictree) C++17
15 / 100
166 ms 53048 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
#define g4(a) get<4>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using db = double;
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using iii = tuple<int, int, int>;
using iiii = tuple<int, int, int, int>;
using iiiii = tuple<int, int, int, int, int>;
template<class key, class value = null_type, class cmp = less<key> >
using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

int n, m, k, ans;
vector<int> adj[100005];
vector<ii> vec[100005];
map<int, int> M[100005], mpp[100005];

void dp(int u) {
	for (auto v : adj[u]) {
		dp(v);
		if (M[u].size() < M[v].size()) swap(M[u], M[v]);
		for (auto i : M[v]) M[u][i.first] += i.second;
	}
	int cur = 0;
	vector<int> eval;
	auto it = M[u].begin();
	for (auto [t, val] : vec[u]) {
		while (it != M[u].end() && it->first <= t) {
			cur += val;
			++it;
		}
		eval.pb(cur);
	}
	reverse(eval.begin(), eval.end());
	reverse(vec[u].begin(), vec[u].end());
	for (int i = 0; i < (int)vec[u].size(); i++) {
		vector<map<int, int>::iterator> to_del;
		vector<ii> to_add;
		auto [t, val] = vec[u][i];
		M[u][t] += val;
		auto it = M[u].find(t);
		++it;
		int sf = 0;
		while (it != M[u].end()) {
			if (sf + it->second <= val) {
				to_del.pb(it);
				sf += it->second;
			} else {
				to_del.pb(it);
				to_add.eb(it->first, sf + it->second - val);
			}
			++it;
		}
		for (auto it : to_del) M[u].erase(it);
		for (auto j : to_add) M[u][j.first] += j.second;
	}
	//~ cout << "NODE " << u << '\n';
	//~ for (auto [a, b] : M[u]) cout << a << ' ' << b << '\n';
}

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m >> k;
	for (int i = 2, p; i <= n; i++) {
		cin >> p;
		adj[p].pb(i);
	}
	for (int i = 1, v, d, w; i <= m; i++) {
		cin >> v >> d >> w;
		mpp[v][d] += w;
	}
	for (int i = 1; i <= n; i++) {
		for (auto j : mpp[i]) vec[i].pb(j);
	}
	dp(1);
	for (auto i : M[1]) ans += i.second;
	cout << ans << '\n';
}

Compilation message

magictree.cpp:76:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   76 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14292 KB Output is correct
2 Correct 8 ms 14416 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 8 ms 14420 KB Output is correct
5 Incorrect 7 ms 14412 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 27316 KB Output is correct
2 Correct 55 ms 32808 KB Output is correct
3 Correct 166 ms 52240 KB Output is correct
4 Correct 113 ms 35000 KB Output is correct
5 Correct 143 ms 38404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14676 KB Output is correct
2 Incorrect 8 ms 14680 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 30520 KB Output is correct
2 Correct 119 ms 29800 KB Output is correct
3 Correct 92 ms 38568 KB Output is correct
4 Correct 74 ms 30960 KB Output is correct
5 Correct 88 ms 53048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14292 KB Output is correct
2 Correct 8 ms 14416 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 8 ms 14420 KB Output is correct
5 Incorrect 7 ms 14412 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 15060 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14292 KB Output is correct
2 Correct 8 ms 14416 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 8 ms 14420 KB Output is correct
5 Incorrect 7 ms 14412 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14292 KB Output is correct
2 Correct 8 ms 14416 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 8 ms 14420 KB Output is correct
5 Incorrect 7 ms 14412 KB Output isn't correct
6 Halted 0 ms 0 KB -