Submission #558485

# Submission time Handle Problem Language Result Execution time Memory
558485 2022-05-07T12:59:32 Z kym Worst Reporter 4 (JOI21_worst_reporter4) C++14
79 / 100
543 ms 192564 KB
#include <bits/stdc++.h>
using namespace std;
#define int ll 
#define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i)
#define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
#define reach cerr << "LINE: " << __LINE__ << "\n";
#else
#define db(x)
#define db2(x,y)
#define db3(a,b,c)
#define dbv(v)
#define dbvp(v)
#define dba(a,ss,ee)
#define reach 
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define g0(x) get<0>(x)
#define g1(x) get<1>(x)
#define g2(x) get<2>(x)
#define g3(x) get<3>(x)
typedef pair <ll, ll> pi;
typedef tuple<ll,ll,ll> ti3;
typedef tuple<ll,ll,ll,ll> ti4;
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
template <typename T> void chmax(T& a, const T b) { a=max(a,b); }
template <typename T> void chmin(T& a, const T b) { a=min(a,b); }
const int MAXN = 200005;
int n;
int A[MAXN], H[MAXN], C[MAXN];
vector<int>V[MAXN];
map<int,int> M[MAXN];

void dfs(int x, int p) {
	for(auto v:V[x])if(v!=p) {
		dfs(v,x);
		if(M[v].size() > M[x].size())swap(M[x], M[v]);
		for(auto i:M[v])M[x][i.f] += i.s;
	}
	M[x][0] += C[x];
	M[x][H[x]] -= C[x];
	M[x][H[x]+1] += C[x];
	auto it=M[x].find(H[x]);
	while(it->s < 0) {
		int t=min(-it->s, prev(it)->s);
		(*it).s += t;
		if((*it).s == 0)(*(prev(it))).s -= t;
		else M[x].erase(prev(it));
	}
}

int32_t main() 
{
	IAMSPEED
	cin >> n;
	reach
	FOR(i,1,n) cin >> A[i] >> H[i] >> C[i];
	FOR(i,1,n) {
		if(i!=A[i])V[A[i]].pb(i);
	}
	
	dfs(1,-1);
	cout << M[1][0];
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14368 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 15 ms 16820 KB Output is correct
6 Correct 14 ms 15988 KB Output is correct
7 Correct 14 ms 15568 KB Output is correct
8 Correct 19 ms 16980 KB Output is correct
9 Correct 14 ms 15956 KB Output is correct
10 Correct 12 ms 15464 KB Output is correct
11 Correct 10 ms 15164 KB Output is correct
12 Correct 11 ms 15456 KB Output is correct
13 Correct 9 ms 15444 KB Output is correct
14 Correct 11 ms 15204 KB Output is correct
15 Correct 11 ms 15168 KB Output is correct
16 Correct 17 ms 17528 KB Output is correct
17 Correct 15 ms 16340 KB Output is correct
18 Correct 13 ms 15204 KB Output is correct
19 Correct 14 ms 15812 KB Output is correct
20 Correct 11 ms 15572 KB Output is correct
21 Correct 13 ms 15460 KB Output is correct
22 Correct 14 ms 16276 KB Output is correct
23 Correct 11 ms 15584 KB Output is correct
24 Correct 12 ms 15956 KB Output is correct
25 Correct 10 ms 15508 KB Output is correct
26 Correct 13 ms 16104 KB Output is correct
27 Correct 16 ms 16004 KB Output is correct
28 Correct 12 ms 15956 KB Output is correct
29 Correct 13 ms 15956 KB Output is correct
30 Correct 13 ms 16092 KB Output is correct
31 Correct 12 ms 16084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14368 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 15 ms 16820 KB Output is correct
6 Correct 14 ms 15988 KB Output is correct
7 Correct 14 ms 15568 KB Output is correct
8 Correct 19 ms 16980 KB Output is correct
9 Correct 14 ms 15956 KB Output is correct
10 Correct 12 ms 15464 KB Output is correct
11 Correct 10 ms 15164 KB Output is correct
12 Correct 11 ms 15456 KB Output is correct
13 Correct 9 ms 15444 KB Output is correct
14 Correct 11 ms 15204 KB Output is correct
15 Correct 11 ms 15168 KB Output is correct
16 Correct 17 ms 17528 KB Output is correct
17 Correct 15 ms 16340 KB Output is correct
18 Correct 13 ms 15204 KB Output is correct
19 Correct 14 ms 15812 KB Output is correct
20 Correct 11 ms 15572 KB Output is correct
21 Correct 13 ms 15460 KB Output is correct
22 Correct 14 ms 16276 KB Output is correct
23 Correct 11 ms 15584 KB Output is correct
24 Correct 12 ms 15956 KB Output is correct
25 Correct 10 ms 15508 KB Output is correct
26 Correct 13 ms 16104 KB Output is correct
27 Correct 16 ms 16004 KB Output is correct
28 Correct 12 ms 15956 KB Output is correct
29 Correct 13 ms 15956 KB Output is correct
30 Correct 13 ms 16092 KB Output is correct
31 Correct 12 ms 16084 KB Output is correct
32 Correct 16 ms 16844 KB Output is correct
33 Correct 486 ms 142992 KB Output is correct
34 Correct 341 ms 93236 KB Output is correct
35 Correct 490 ms 137080 KB Output is correct
36 Correct 363 ms 93320 KB Output is correct
37 Correct 205 ms 55244 KB Output is correct
38 Correct 183 ms 46396 KB Output is correct
39 Correct 183 ms 58732 KB Output is correct
40 Correct 152 ms 58736 KB Output is correct
41 Correct 126 ms 58684 KB Output is correct
42 Correct 171 ms 44804 KB Output is correct
43 Correct 166 ms 44696 KB Output is correct
44 Correct 543 ms 192564 KB Output is correct
45 Correct 357 ms 121328 KB Output is correct
46 Correct 118 ms 45984 KB Output is correct
47 Correct 324 ms 74080 KB Output is correct
48 Correct 162 ms 60188 KB Output is correct
49 Correct 111 ms 60024 KB Output is correct
50 Correct 321 ms 87432 KB Output is correct
51 Correct 143 ms 62604 KB Output is correct
52 Correct 318 ms 75396 KB Output is correct
53 Correct 150 ms 61100 KB Output is correct
54 Correct 316 ms 83812 KB Output is correct
55 Correct 245 ms 78440 KB Output is correct
56 Correct 221 ms 78348 KB Output is correct
57 Correct 204 ms 79536 KB Output is correct
58 Correct 238 ms 81436 KB Output is correct
59 Correct 241 ms 81356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14368 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 15 ms 16820 KB Output is correct
6 Correct 14 ms 15988 KB Output is correct
7 Correct 14 ms 15568 KB Output is correct
8 Correct 19 ms 16980 KB Output is correct
9 Correct 14 ms 15956 KB Output is correct
10 Correct 12 ms 15464 KB Output is correct
11 Correct 10 ms 15164 KB Output is correct
12 Correct 11 ms 15456 KB Output is correct
13 Correct 9 ms 15444 KB Output is correct
14 Correct 11 ms 15204 KB Output is correct
15 Correct 11 ms 15168 KB Output is correct
16 Correct 17 ms 17528 KB Output is correct
17 Correct 15 ms 16340 KB Output is correct
18 Correct 13 ms 15204 KB Output is correct
19 Correct 14 ms 15812 KB Output is correct
20 Correct 11 ms 15572 KB Output is correct
21 Correct 13 ms 15460 KB Output is correct
22 Correct 14 ms 16276 KB Output is correct
23 Correct 11 ms 15584 KB Output is correct
24 Correct 12 ms 15956 KB Output is correct
25 Correct 10 ms 15508 KB Output is correct
26 Correct 13 ms 16104 KB Output is correct
27 Correct 16 ms 16004 KB Output is correct
28 Correct 12 ms 15956 KB Output is correct
29 Correct 13 ms 15956 KB Output is correct
30 Correct 13 ms 16092 KB Output is correct
31 Correct 12 ms 16084 KB Output is correct
32 Correct 16 ms 16844 KB Output is correct
33 Correct 486 ms 142992 KB Output is correct
34 Correct 341 ms 93236 KB Output is correct
35 Correct 490 ms 137080 KB Output is correct
36 Correct 363 ms 93320 KB Output is correct
37 Correct 205 ms 55244 KB Output is correct
38 Correct 183 ms 46396 KB Output is correct
39 Correct 183 ms 58732 KB Output is correct
40 Correct 152 ms 58736 KB Output is correct
41 Correct 126 ms 58684 KB Output is correct
42 Correct 171 ms 44804 KB Output is correct
43 Correct 166 ms 44696 KB Output is correct
44 Correct 543 ms 192564 KB Output is correct
45 Correct 357 ms 121328 KB Output is correct
46 Correct 118 ms 45984 KB Output is correct
47 Correct 324 ms 74080 KB Output is correct
48 Correct 162 ms 60188 KB Output is correct
49 Correct 111 ms 60024 KB Output is correct
50 Correct 321 ms 87432 KB Output is correct
51 Correct 143 ms 62604 KB Output is correct
52 Correct 318 ms 75396 KB Output is correct
53 Correct 150 ms 61100 KB Output is correct
54 Correct 316 ms 83812 KB Output is correct
55 Correct 245 ms 78440 KB Output is correct
56 Correct 221 ms 78348 KB Output is correct
57 Correct 204 ms 79536 KB Output is correct
58 Correct 238 ms 81436 KB Output is correct
59 Correct 241 ms 81356 KB Output is correct
60 Correct 7 ms 14420 KB Output is correct
61 Incorrect 7 ms 14420 KB Output isn't correct
62 Halted 0 ms 0 KB -