/*
ID: ekrem
LANG: C++
TASK: Fireworks
*/
#include <algorithm>
#include <iostream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define foreach(kk,gg) for(__typeof(gg.begin())kk=gg.begin();kk!=gg.end();kk++)
#define dbgs(x) cerr << (#x) << " --> " << (x) << ' '
#define dbg(x) cerr << (#x) << " --> " << (x) << endl
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)
#define SET(a, b) memset(a, b, sizeof a)
#define heap priority_queue
#define orta (bas+son>>1)
#define endll puts("")
#define mp make_pair
#define pb push_back
#define sag (k+k+1)
#define sol (k+k)
#define endl '\n'
#define nd second
#define st first
#define y1 ekrem
#define y2 merke
typedef int don;
#define int long long int
inline int read(){int x;scanf(" %lld",&x);return x;}
typedef pair < int , int > ii;
typedef vector < int > vi;
typedef vector < ii > vii;
const int inf = 1e9 + 7;
const int linf = 1e18 + 7;
const int N = 3e5 + 5;
int n, m, p[N], c[N], a[N], b[N];
heap < int > h[N];
void ekle(int par, int coc){
a[par] += a[coc];
b[par] += b[coc];
heap < int > x;
if(h[par].size() > h[coc].size()){
x = h[par];
while(!h[coc].empty()){
int t = h[coc].top();h[coc].pop();
x.push(t);
}
} else{
x = h[coc];
while(!h[par].empty()){
int t = h[par].top();h[par].pop();
x.push(t);
}
}
h[par] = x;
}
don main(){
// freopen("input.in", "r", stdin);freopen("input.out", "w", stdout);
n = read();
m = read();
FOR(i, 2, n + m){
p[i] = read();
c[i] = read();
}
ROF(i, n + m, n + 1){//Yapraklar
a[i] = 1;
b[i] = -c[i];
h[i].push(c[i]);
h[i].push(c[i]);
ekle(p[i], i);
}
ROF(i, n, 2){
while(a[i] > 1){
a[i]--;
b[i] += h[i].top();h[i].pop();
}
int bir = h[i].top();h[i].pop();
int iki = h[i].top();h[i].pop();
h[i].push(bir + c[i]);
h[i].push(iki + c[i]);
b[i] -= c[i];//Bu ne
ekle(p[i], i);
}
while(a[1] > 0){
a[1]--;
b[1] += h[1].top();h[1].pop();
}
cout << b[1] << endl;
return 0;
}
Compilation message
fireworks.cpp: In function 'long long int read()':
fireworks.cpp:45:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
inline int read(){int x;scanf(" %lld",&x);return x;}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9720 KB |
Output is correct |
2 |
Correct |
10 ms |
9824 KB |
Output is correct |
3 |
Correct |
10 ms |
9824 KB |
Output is correct |
4 |
Correct |
9 ms |
9824 KB |
Output is correct |
5 |
Correct |
10 ms |
9948 KB |
Output is correct |
6 |
Correct |
9 ms |
9948 KB |
Output is correct |
7 |
Correct |
9 ms |
9948 KB |
Output is correct |
8 |
Correct |
12 ms |
9948 KB |
Output is correct |
9 |
Correct |
10 ms |
10020 KB |
Output is correct |
10 |
Correct |
11 ms |
10020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
10020 KB |
Output is correct |
2 |
Correct |
9 ms |
10020 KB |
Output is correct |
3 |
Correct |
10 ms |
10020 KB |
Output is correct |
4 |
Correct |
10 ms |
10020 KB |
Output is correct |
5 |
Correct |
10 ms |
10020 KB |
Output is correct |
6 |
Correct |
12 ms |
10020 KB |
Output is correct |
7 |
Correct |
10 ms |
10020 KB |
Output is correct |
8 |
Correct |
10 ms |
10092 KB |
Output is correct |
9 |
Correct |
10 ms |
10092 KB |
Output is correct |
10 |
Correct |
14 ms |
10092 KB |
Output is correct |
11 |
Correct |
9 ms |
10092 KB |
Output is correct |
12 |
Correct |
10 ms |
10092 KB |
Output is correct |
13 |
Correct |
10 ms |
10092 KB |
Output is correct |
14 |
Correct |
10 ms |
10092 KB |
Output is correct |
15 |
Correct |
10 ms |
10092 KB |
Output is correct |
16 |
Correct |
12 ms |
10092 KB |
Output is correct |
17 |
Correct |
11 ms |
10092 KB |
Output is correct |
18 |
Correct |
10 ms |
10092 KB |
Output is correct |
19 |
Correct |
13 ms |
10092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9720 KB |
Output is correct |
2 |
Correct |
10 ms |
9824 KB |
Output is correct |
3 |
Correct |
10 ms |
9824 KB |
Output is correct |
4 |
Correct |
9 ms |
9824 KB |
Output is correct |
5 |
Correct |
10 ms |
9948 KB |
Output is correct |
6 |
Correct |
9 ms |
9948 KB |
Output is correct |
7 |
Correct |
9 ms |
9948 KB |
Output is correct |
8 |
Correct |
12 ms |
9948 KB |
Output is correct |
9 |
Correct |
10 ms |
10020 KB |
Output is correct |
10 |
Correct |
11 ms |
10020 KB |
Output is correct |
11 |
Correct |
9 ms |
10020 KB |
Output is correct |
12 |
Correct |
9 ms |
10020 KB |
Output is correct |
13 |
Correct |
10 ms |
10020 KB |
Output is correct |
14 |
Correct |
10 ms |
10020 KB |
Output is correct |
15 |
Correct |
10 ms |
10020 KB |
Output is correct |
16 |
Correct |
12 ms |
10020 KB |
Output is correct |
17 |
Correct |
10 ms |
10020 KB |
Output is correct |
18 |
Correct |
10 ms |
10092 KB |
Output is correct |
19 |
Correct |
10 ms |
10092 KB |
Output is correct |
20 |
Correct |
14 ms |
10092 KB |
Output is correct |
21 |
Correct |
9 ms |
10092 KB |
Output is correct |
22 |
Correct |
10 ms |
10092 KB |
Output is correct |
23 |
Correct |
10 ms |
10092 KB |
Output is correct |
24 |
Correct |
10 ms |
10092 KB |
Output is correct |
25 |
Correct |
10 ms |
10092 KB |
Output is correct |
26 |
Correct |
12 ms |
10092 KB |
Output is correct |
27 |
Correct |
11 ms |
10092 KB |
Output is correct |
28 |
Correct |
10 ms |
10092 KB |
Output is correct |
29 |
Correct |
13 ms |
10092 KB |
Output is correct |
30 |
Correct |
14 ms |
10092 KB |
Output is correct |
31 |
Correct |
11 ms |
10224 KB |
Output is correct |
32 |
Correct |
11 ms |
10224 KB |
Output is correct |
33 |
Correct |
11 ms |
10476 KB |
Output is correct |
34 |
Correct |
12 ms |
10604 KB |
Output is correct |
35 |
Correct |
13 ms |
11372 KB |
Output is correct |
36 |
Correct |
14 ms |
11372 KB |
Output is correct |
37 |
Correct |
14 ms |
11372 KB |
Output is correct |
38 |
Correct |
20 ms |
12780 KB |
Output is correct |
39 |
Correct |
15 ms |
12780 KB |
Output is correct |
40 |
Correct |
15 ms |
12780 KB |
Output is correct |
41 |
Correct |
12 ms |
12780 KB |
Output is correct |
42 |
Correct |
12 ms |
12780 KB |
Output is correct |
43 |
Correct |
36 ms |
37868 KB |
Output is correct |
44 |
Correct |
32 ms |
37868 KB |
Output is correct |
45 |
Correct |
31 ms |
37868 KB |
Output is correct |
46 |
Correct |
16 ms |
37868 KB |
Output is correct |
47 |
Correct |
17 ms |
37868 KB |
Output is correct |
48 |
Correct |
19 ms |
37868 KB |
Output is correct |
49 |
Correct |
19 ms |
37868 KB |
Output is correct |
50 |
Correct |
29 ms |
37868 KB |
Output is correct |
51 |
Correct |
30 ms |
37868 KB |
Output is correct |
52 |
Correct |
24 ms |
37868 KB |
Output is correct |
53 |
Correct |
23 ms |
37868 KB |
Output is correct |
54 |
Correct |
108 ms |
37868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9720 KB |
Output is correct |
2 |
Correct |
10 ms |
9824 KB |
Output is correct |
3 |
Correct |
10 ms |
9824 KB |
Output is correct |
4 |
Correct |
9 ms |
9824 KB |
Output is correct |
5 |
Correct |
10 ms |
9948 KB |
Output is correct |
6 |
Correct |
9 ms |
9948 KB |
Output is correct |
7 |
Correct |
9 ms |
9948 KB |
Output is correct |
8 |
Correct |
12 ms |
9948 KB |
Output is correct |
9 |
Correct |
10 ms |
10020 KB |
Output is correct |
10 |
Correct |
11 ms |
10020 KB |
Output is correct |
11 |
Correct |
9 ms |
10020 KB |
Output is correct |
12 |
Correct |
9 ms |
10020 KB |
Output is correct |
13 |
Correct |
10 ms |
10020 KB |
Output is correct |
14 |
Correct |
10 ms |
10020 KB |
Output is correct |
15 |
Correct |
10 ms |
10020 KB |
Output is correct |
16 |
Correct |
12 ms |
10020 KB |
Output is correct |
17 |
Correct |
10 ms |
10020 KB |
Output is correct |
18 |
Correct |
10 ms |
10092 KB |
Output is correct |
19 |
Correct |
10 ms |
10092 KB |
Output is correct |
20 |
Correct |
14 ms |
10092 KB |
Output is correct |
21 |
Correct |
9 ms |
10092 KB |
Output is correct |
22 |
Correct |
10 ms |
10092 KB |
Output is correct |
23 |
Correct |
10 ms |
10092 KB |
Output is correct |
24 |
Correct |
10 ms |
10092 KB |
Output is correct |
25 |
Correct |
10 ms |
10092 KB |
Output is correct |
26 |
Correct |
12 ms |
10092 KB |
Output is correct |
27 |
Correct |
11 ms |
10092 KB |
Output is correct |
28 |
Correct |
10 ms |
10092 KB |
Output is correct |
29 |
Correct |
13 ms |
10092 KB |
Output is correct |
30 |
Correct |
14 ms |
10092 KB |
Output is correct |
31 |
Correct |
11 ms |
10224 KB |
Output is correct |
32 |
Correct |
11 ms |
10224 KB |
Output is correct |
33 |
Correct |
11 ms |
10476 KB |
Output is correct |
34 |
Correct |
12 ms |
10604 KB |
Output is correct |
35 |
Correct |
13 ms |
11372 KB |
Output is correct |
36 |
Correct |
14 ms |
11372 KB |
Output is correct |
37 |
Correct |
14 ms |
11372 KB |
Output is correct |
38 |
Correct |
20 ms |
12780 KB |
Output is correct |
39 |
Correct |
15 ms |
12780 KB |
Output is correct |
40 |
Correct |
15 ms |
12780 KB |
Output is correct |
41 |
Correct |
12 ms |
12780 KB |
Output is correct |
42 |
Correct |
12 ms |
12780 KB |
Output is correct |
43 |
Correct |
36 ms |
37868 KB |
Output is correct |
44 |
Correct |
32 ms |
37868 KB |
Output is correct |
45 |
Correct |
31 ms |
37868 KB |
Output is correct |
46 |
Correct |
16 ms |
37868 KB |
Output is correct |
47 |
Correct |
17 ms |
37868 KB |
Output is correct |
48 |
Correct |
19 ms |
37868 KB |
Output is correct |
49 |
Correct |
19 ms |
37868 KB |
Output is correct |
50 |
Correct |
29 ms |
37868 KB |
Output is correct |
51 |
Correct |
30 ms |
37868 KB |
Output is correct |
52 |
Correct |
24 ms |
37868 KB |
Output is correct |
53 |
Correct |
23 ms |
37868 KB |
Output is correct |
54 |
Correct |
108 ms |
37868 KB |
Output is correct |
55 |
Correct |
25 ms |
37868 KB |
Output is correct |
56 |
Correct |
92 ms |
64568 KB |
Output is correct |
57 |
Correct |
172 ms |
120228 KB |
Output is correct |
58 |
Correct |
200 ms |
136980 KB |
Output is correct |
59 |
Correct |
367 ms |
304316 KB |
Output is correct |
60 |
Correct |
415 ms |
304316 KB |
Output is correct |
61 |
Correct |
490 ms |
389288 KB |
Output is correct |
62 |
Correct |
534 ms |
411168 KB |
Output is correct |
63 |
Correct |
560 ms |
411264 KB |
Output is correct |
64 |
Execution timed out |
2094 ms |
524288 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |