#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a))
#define MEM_1(a) memset((a),-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define COMPRESS(a) sort(ALL(a));a.resize(unique(ALL(a))-a.begin())
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<ld> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };
Vi v[200001];
int h[200001],pt[200001];
ll c[200001];
map<int,ll,greater<int>> M[200001];
void dfs(int N){
if(v[N].empty()){
M[N][h[N]]=c[N];
return;
}
for(int next:v[N]){
dfs(next);
int &x=pt[next],&y=pt[N];
if(M[x].size()>M[y].size())swap(x,y);
for(auto [a,b]:M[x]){
M[y][a]+=b;
}
}
int nn=pt[N];
M[nn][h[N]]+=c[N];
ll t=c[N];
auto it=M[nn].upper_bound(h[N]);
while(it!=M[nn].end()){
if(it->Y<t){
t-=it->Y;
it=M[nn].erase(it);
}else{
it->Y-=t;
break;
}
}
}
int main(){
int n;
scanf("%d",&n);
iota(pt,pt+n+1,0);
Vi vv={0};
ll tot=0;
fup(i,1,n,1){
int x;
scanf("%d%d%lld",&x,&h[i],&c[i]);
tot+=c[i];
if(i!=x)v[x].pb(i);
vv.pb(h[i]);
}
COMPRESS(vv);
fup(i,1,n,1)h[i]=lower_bound(ALL(vv),h[i])-vv.begin();
dfs(1);
ll ans=0;
for(auto [a,b]:M[pt[1]])ans+=b;
printf("%lld\n",tot-ans);
}
Compilation message
worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
worst_reporter2.cpp:80:2: note: in expansion of macro 'fup'
80 | fup(i,1,n,1){
| ^~~
worst_reporter2.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
worst_reporter2.cpp:88:2: note: in expansion of macro 'fup'
88 | fup(i,1,n,1)h[i]=lower_bound(ALL(vv),h[i])-vv.begin();
| ^~~
worst_reporter2.cpp:76:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
76 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
worst_reporter2.cpp:82:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
82 | scanf("%d%d%lld",&x,&h[i],&c[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14284 KB |
Output is correct |
2 |
Correct |
8 ms |
14284 KB |
Output is correct |
3 |
Correct |
8 ms |
14284 KB |
Output is correct |
4 |
Correct |
8 ms |
14284 KB |
Output is correct |
5 |
Correct |
14 ms |
15436 KB |
Output is correct |
6 |
Correct |
14 ms |
15112 KB |
Output is correct |
7 |
Correct |
12 ms |
14884 KB |
Output is correct |
8 |
Correct |
15 ms |
15612 KB |
Output is correct |
9 |
Correct |
14 ms |
15084 KB |
Output is correct |
10 |
Correct |
13 ms |
14808 KB |
Output is correct |
11 |
Correct |
11 ms |
14668 KB |
Output is correct |
12 |
Correct |
13 ms |
15376 KB |
Output is correct |
13 |
Correct |
12 ms |
15292 KB |
Output is correct |
14 |
Correct |
13 ms |
14924 KB |
Output is correct |
15 |
Correct |
12 ms |
14924 KB |
Output is correct |
16 |
Correct |
16 ms |
15856 KB |
Output is correct |
17 |
Correct |
14 ms |
15264 KB |
Output is correct |
18 |
Correct |
12 ms |
14668 KB |
Output is correct |
19 |
Correct |
14 ms |
15264 KB |
Output is correct |
20 |
Correct |
12 ms |
15052 KB |
Output is correct |
21 |
Correct |
11 ms |
15080 KB |
Output is correct |
22 |
Correct |
13 ms |
15148 KB |
Output is correct |
23 |
Correct |
11 ms |
14812 KB |
Output is correct |
24 |
Correct |
14 ms |
15268 KB |
Output is correct |
25 |
Correct |
13 ms |
15052 KB |
Output is correct |
26 |
Correct |
13 ms |
15656 KB |
Output is correct |
27 |
Correct |
13 ms |
15228 KB |
Output is correct |
28 |
Correct |
12 ms |
15308 KB |
Output is correct |
29 |
Correct |
12 ms |
15436 KB |
Output is correct |
30 |
Correct |
13 ms |
15380 KB |
Output is correct |
31 |
Correct |
13 ms |
15436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14284 KB |
Output is correct |
2 |
Correct |
8 ms |
14284 KB |
Output is correct |
3 |
Correct |
8 ms |
14284 KB |
Output is correct |
4 |
Correct |
8 ms |
14284 KB |
Output is correct |
5 |
Correct |
14 ms |
15436 KB |
Output is correct |
6 |
Correct |
14 ms |
15112 KB |
Output is correct |
7 |
Correct |
12 ms |
14884 KB |
Output is correct |
8 |
Correct |
15 ms |
15612 KB |
Output is correct |
9 |
Correct |
14 ms |
15084 KB |
Output is correct |
10 |
Correct |
13 ms |
14808 KB |
Output is correct |
11 |
Correct |
11 ms |
14668 KB |
Output is correct |
12 |
Correct |
13 ms |
15376 KB |
Output is correct |
13 |
Correct |
12 ms |
15292 KB |
Output is correct |
14 |
Correct |
13 ms |
14924 KB |
Output is correct |
15 |
Correct |
12 ms |
14924 KB |
Output is correct |
16 |
Correct |
16 ms |
15856 KB |
Output is correct |
17 |
Correct |
14 ms |
15264 KB |
Output is correct |
18 |
Correct |
12 ms |
14668 KB |
Output is correct |
19 |
Correct |
14 ms |
15264 KB |
Output is correct |
20 |
Correct |
12 ms |
15052 KB |
Output is correct |
21 |
Correct |
11 ms |
15080 KB |
Output is correct |
22 |
Correct |
13 ms |
15148 KB |
Output is correct |
23 |
Correct |
11 ms |
14812 KB |
Output is correct |
24 |
Correct |
14 ms |
15268 KB |
Output is correct |
25 |
Correct |
13 ms |
15052 KB |
Output is correct |
26 |
Correct |
13 ms |
15656 KB |
Output is correct |
27 |
Correct |
13 ms |
15228 KB |
Output is correct |
28 |
Correct |
12 ms |
15308 KB |
Output is correct |
29 |
Correct |
12 ms |
15436 KB |
Output is correct |
30 |
Correct |
13 ms |
15380 KB |
Output is correct |
31 |
Correct |
13 ms |
15436 KB |
Output is correct |
32 |
Correct |
15 ms |
15524 KB |
Output is correct |
33 |
Correct |
426 ms |
75856 KB |
Output is correct |
34 |
Correct |
315 ms |
52920 KB |
Output is correct |
35 |
Correct |
413 ms |
74900 KB |
Output is correct |
36 |
Correct |
318 ms |
53044 KB |
Output is correct |
37 |
Correct |
210 ms |
34028 KB |
Output is correct |
38 |
Correct |
177 ms |
29620 KB |
Output is correct |
39 |
Correct |
215 ms |
54688 KB |
Output is correct |
40 |
Correct |
182 ms |
54712 KB |
Output is correct |
41 |
Correct |
133 ms |
54704 KB |
Output is correct |
42 |
Correct |
209 ms |
40732 KB |
Output is correct |
43 |
Correct |
177 ms |
40604 KB |
Output is correct |
44 |
Correct |
388 ms |
102788 KB |
Output is correct |
45 |
Correct |
263 ms |
67180 KB |
Output is correct |
46 |
Correct |
118 ms |
29592 KB |
Output is correct |
47 |
Correct |
302 ms |
50668 KB |
Output is correct |
48 |
Correct |
169 ms |
43688 KB |
Output is correct |
49 |
Correct |
130 ms |
43576 KB |
Output is correct |
50 |
Correct |
335 ms |
46056 KB |
Output is correct |
51 |
Correct |
146 ms |
33576 KB |
Output is correct |
52 |
Correct |
336 ms |
51168 KB |
Output is correct |
53 |
Correct |
163 ms |
44248 KB |
Output is correct |
54 |
Correct |
245 ms |
67128 KB |
Output is correct |
55 |
Correct |
244 ms |
53064 KB |
Output is correct |
56 |
Correct |
223 ms |
58976 KB |
Output is correct |
57 |
Correct |
203 ms |
62008 KB |
Output is correct |
58 |
Correct |
250 ms |
59308 KB |
Output is correct |
59 |
Correct |
251 ms |
59316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14284 KB |
Output is correct |
2 |
Correct |
8 ms |
14284 KB |
Output is correct |
3 |
Correct |
8 ms |
14284 KB |
Output is correct |
4 |
Correct |
8 ms |
14284 KB |
Output is correct |
5 |
Correct |
14 ms |
15436 KB |
Output is correct |
6 |
Correct |
14 ms |
15112 KB |
Output is correct |
7 |
Correct |
12 ms |
14884 KB |
Output is correct |
8 |
Correct |
15 ms |
15612 KB |
Output is correct |
9 |
Correct |
14 ms |
15084 KB |
Output is correct |
10 |
Correct |
13 ms |
14808 KB |
Output is correct |
11 |
Correct |
11 ms |
14668 KB |
Output is correct |
12 |
Correct |
13 ms |
15376 KB |
Output is correct |
13 |
Correct |
12 ms |
15292 KB |
Output is correct |
14 |
Correct |
13 ms |
14924 KB |
Output is correct |
15 |
Correct |
12 ms |
14924 KB |
Output is correct |
16 |
Correct |
16 ms |
15856 KB |
Output is correct |
17 |
Correct |
14 ms |
15264 KB |
Output is correct |
18 |
Correct |
12 ms |
14668 KB |
Output is correct |
19 |
Correct |
14 ms |
15264 KB |
Output is correct |
20 |
Correct |
12 ms |
15052 KB |
Output is correct |
21 |
Correct |
11 ms |
15080 KB |
Output is correct |
22 |
Correct |
13 ms |
15148 KB |
Output is correct |
23 |
Correct |
11 ms |
14812 KB |
Output is correct |
24 |
Correct |
14 ms |
15268 KB |
Output is correct |
25 |
Correct |
13 ms |
15052 KB |
Output is correct |
26 |
Correct |
13 ms |
15656 KB |
Output is correct |
27 |
Correct |
13 ms |
15228 KB |
Output is correct |
28 |
Correct |
12 ms |
15308 KB |
Output is correct |
29 |
Correct |
12 ms |
15436 KB |
Output is correct |
30 |
Correct |
13 ms |
15380 KB |
Output is correct |
31 |
Correct |
13 ms |
15436 KB |
Output is correct |
32 |
Correct |
15 ms |
15524 KB |
Output is correct |
33 |
Correct |
426 ms |
75856 KB |
Output is correct |
34 |
Correct |
315 ms |
52920 KB |
Output is correct |
35 |
Correct |
413 ms |
74900 KB |
Output is correct |
36 |
Correct |
318 ms |
53044 KB |
Output is correct |
37 |
Correct |
210 ms |
34028 KB |
Output is correct |
38 |
Correct |
177 ms |
29620 KB |
Output is correct |
39 |
Correct |
215 ms |
54688 KB |
Output is correct |
40 |
Correct |
182 ms |
54712 KB |
Output is correct |
41 |
Correct |
133 ms |
54704 KB |
Output is correct |
42 |
Correct |
209 ms |
40732 KB |
Output is correct |
43 |
Correct |
177 ms |
40604 KB |
Output is correct |
44 |
Correct |
388 ms |
102788 KB |
Output is correct |
45 |
Correct |
263 ms |
67180 KB |
Output is correct |
46 |
Correct |
118 ms |
29592 KB |
Output is correct |
47 |
Correct |
302 ms |
50668 KB |
Output is correct |
48 |
Correct |
169 ms |
43688 KB |
Output is correct |
49 |
Correct |
130 ms |
43576 KB |
Output is correct |
50 |
Correct |
335 ms |
46056 KB |
Output is correct |
51 |
Correct |
146 ms |
33576 KB |
Output is correct |
52 |
Correct |
336 ms |
51168 KB |
Output is correct |
53 |
Correct |
163 ms |
44248 KB |
Output is correct |
54 |
Correct |
245 ms |
67128 KB |
Output is correct |
55 |
Correct |
244 ms |
53064 KB |
Output is correct |
56 |
Correct |
223 ms |
58976 KB |
Output is correct |
57 |
Correct |
203 ms |
62008 KB |
Output is correct |
58 |
Correct |
250 ms |
59308 KB |
Output is correct |
59 |
Correct |
251 ms |
59316 KB |
Output is correct |
60 |
Runtime error |
301 ms |
524292 KB |
Execution killed with signal 9 |
61 |
Halted |
0 ms |
0 KB |
- |