답안 #139933

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
139933 2019-08-01T16:54:24 Z nvmdava Fireworks (APIO16_fireworks) C++17
100 / 100
457 ms 93604 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int p[300005];
int b[300005];
ll a[300005];

priority_queue<pair<long long, int> > pq[300005];
vector<int> ch[300005];

void dfs(int v){
   int big = 0;
   for(int& x : ch[v]){
      dfs(x);
      if(pq[big].size() < pq[x].size()) big = x;
   }
   if(big == 0){
      pq[v].push({0, -1});
      pq[v].push({a[v], 1});
      pq[v].push({a[v], 1});
      return;
   }
   swap(pq[big], pq[v]);
   int g = ch[v].size();
   for(auto& x : ch[v]){
      if(x == big) continue;
      while(!pq[x].empty()){
         pq[v].push(pq[x].top());
         pq[x].pop();
      }
   }
   ll t, t2;
   while(g > -1){
      t2 = t;
      t = pq[v].top().first;
      g -= pq[v].top().second;
      pq[v].pop();
   }
   pq[v].push({t + a[v], 1});
   pq[v].push({t + a[v] + t2 - t, 1});
}

int main(){
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   int n, m;
   cin>>n>>m;
   ll y = 0;
   for(int i = 2; i <= n + m; i++){
      cin>>p[i]>>a[i];
      y += a[i];
      ch[p[i]].push_back(i);
   }

   dfs(1);
   ll t = pq[1].top().first;
   while(!pq[1].empty()){
      y += (t - pq[1].top().first) * pq[1].top().second;
      pq[1].pop();
   }
   cout<<y;
}

Compilation message

fireworks.cpp: In function 'void dfs(int)':
fireworks.cpp:41:25: warning: 't2' may be used uninitialized in this function [-Wmaybe-uninitialized]
    pq[v].push({t + a[v] + t2 - t, 1});
                ~~~~~~~~~^~~~
fireworks.cpp:40:18: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
    pq[v].push({t + a[v], 1});
                ~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 16760 KB Output is correct
2 Correct 17 ms 16760 KB Output is correct
3 Correct 16 ms 16760 KB Output is correct
4 Correct 16 ms 16760 KB Output is correct
5 Correct 16 ms 16760 KB Output is correct
6 Correct 17 ms 16888 KB Output is correct
7 Correct 16 ms 16888 KB Output is correct
8 Correct 16 ms 16888 KB Output is correct
9 Correct 17 ms 16760 KB Output is correct
10 Correct 17 ms 16860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 16760 KB Output is correct
2 Correct 17 ms 16760 KB Output is correct
3 Correct 17 ms 16760 KB Output is correct
4 Correct 18 ms 16760 KB Output is correct
5 Correct 17 ms 16760 KB Output is correct
6 Correct 17 ms 16732 KB Output is correct
7 Correct 17 ms 16760 KB Output is correct
8 Correct 17 ms 16888 KB Output is correct
9 Correct 17 ms 16764 KB Output is correct
10 Correct 17 ms 16888 KB Output is correct
11 Correct 17 ms 16804 KB Output is correct
12 Correct 22 ms 16908 KB Output is correct
13 Correct 17 ms 16764 KB Output is correct
14 Correct 17 ms 16888 KB Output is correct
15 Correct 20 ms 16864 KB Output is correct
16 Correct 17 ms 16760 KB Output is correct
17 Correct 17 ms 16888 KB Output is correct
18 Correct 17 ms 16888 KB Output is correct
19 Correct 17 ms 16888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 16760 KB Output is correct
2 Correct 17 ms 16760 KB Output is correct
3 Correct 16 ms 16760 KB Output is correct
4 Correct 16 ms 16760 KB Output is correct
5 Correct 16 ms 16760 KB Output is correct
6 Correct 17 ms 16888 KB Output is correct
7 Correct 16 ms 16888 KB Output is correct
8 Correct 16 ms 16888 KB Output is correct
9 Correct 17 ms 16760 KB Output is correct
10 Correct 17 ms 16860 KB Output is correct
11 Correct 17 ms 16760 KB Output is correct
12 Correct 17 ms 16760 KB Output is correct
13 Correct 17 ms 16760 KB Output is correct
14 Correct 18 ms 16760 KB Output is correct
15 Correct 17 ms 16760 KB Output is correct
16 Correct 17 ms 16732 KB Output is correct
17 Correct 17 ms 16760 KB Output is correct
18 Correct 17 ms 16888 KB Output is correct
19 Correct 17 ms 16764 KB Output is correct
20 Correct 17 ms 16888 KB Output is correct
21 Correct 17 ms 16804 KB Output is correct
22 Correct 22 ms 16908 KB Output is correct
23 Correct 17 ms 16764 KB Output is correct
24 Correct 17 ms 16888 KB Output is correct
25 Correct 20 ms 16864 KB Output is correct
26 Correct 17 ms 16760 KB Output is correct
27 Correct 17 ms 16888 KB Output is correct
28 Correct 17 ms 16888 KB Output is correct
29 Correct 17 ms 16888 KB Output is correct
30 Correct 21 ms 16888 KB Output is correct
31 Correct 18 ms 16888 KB Output is correct
32 Correct 18 ms 17016 KB Output is correct
33 Correct 19 ms 17016 KB Output is correct
34 Correct 23 ms 17144 KB Output is correct
35 Correct 21 ms 17272 KB Output is correct
36 Correct 21 ms 17276 KB Output is correct
37 Correct 21 ms 17400 KB Output is correct
38 Correct 22 ms 17528 KB Output is correct
39 Correct 22 ms 17400 KB Output is correct
40 Correct 20 ms 17916 KB Output is correct
41 Correct 20 ms 17912 KB Output is correct
42 Correct 20 ms 17144 KB Output is correct
43 Correct 21 ms 17660 KB Output is correct
44 Correct 22 ms 17656 KB Output is correct
45 Correct 23 ms 17656 KB Output is correct
46 Correct 23 ms 18040 KB Output is correct
47 Correct 23 ms 17912 KB Output is correct
48 Correct 22 ms 17784 KB Output is correct
49 Correct 22 ms 17784 KB Output is correct
50 Correct 21 ms 17528 KB Output is correct
51 Correct 21 ms 17528 KB Output is correct
52 Correct 22 ms 17656 KB Output is correct
53 Correct 22 ms 17788 KB Output is correct
54 Correct 22 ms 17784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 16760 KB Output is correct
2 Correct 17 ms 16760 KB Output is correct
3 Correct 16 ms 16760 KB Output is correct
4 Correct 16 ms 16760 KB Output is correct
5 Correct 16 ms 16760 KB Output is correct
6 Correct 17 ms 16888 KB Output is correct
7 Correct 16 ms 16888 KB Output is correct
8 Correct 16 ms 16888 KB Output is correct
9 Correct 17 ms 16760 KB Output is correct
10 Correct 17 ms 16860 KB Output is correct
11 Correct 17 ms 16760 KB Output is correct
12 Correct 17 ms 16760 KB Output is correct
13 Correct 17 ms 16760 KB Output is correct
14 Correct 18 ms 16760 KB Output is correct
15 Correct 17 ms 16760 KB Output is correct
16 Correct 17 ms 16732 KB Output is correct
17 Correct 17 ms 16760 KB Output is correct
18 Correct 17 ms 16888 KB Output is correct
19 Correct 17 ms 16764 KB Output is correct
20 Correct 17 ms 16888 KB Output is correct
21 Correct 17 ms 16804 KB Output is correct
22 Correct 22 ms 16908 KB Output is correct
23 Correct 17 ms 16764 KB Output is correct
24 Correct 17 ms 16888 KB Output is correct
25 Correct 20 ms 16864 KB Output is correct
26 Correct 17 ms 16760 KB Output is correct
27 Correct 17 ms 16888 KB Output is correct
28 Correct 17 ms 16888 KB Output is correct
29 Correct 17 ms 16888 KB Output is correct
30 Correct 21 ms 16888 KB Output is correct
31 Correct 18 ms 16888 KB Output is correct
32 Correct 18 ms 17016 KB Output is correct
33 Correct 19 ms 17016 KB Output is correct
34 Correct 23 ms 17144 KB Output is correct
35 Correct 21 ms 17272 KB Output is correct
36 Correct 21 ms 17276 KB Output is correct
37 Correct 21 ms 17400 KB Output is correct
38 Correct 22 ms 17528 KB Output is correct
39 Correct 22 ms 17400 KB Output is correct
40 Correct 20 ms 17916 KB Output is correct
41 Correct 20 ms 17912 KB Output is correct
42 Correct 20 ms 17144 KB Output is correct
43 Correct 21 ms 17660 KB Output is correct
44 Correct 22 ms 17656 KB Output is correct
45 Correct 23 ms 17656 KB Output is correct
46 Correct 23 ms 18040 KB Output is correct
47 Correct 23 ms 17912 KB Output is correct
48 Correct 22 ms 17784 KB Output is correct
49 Correct 22 ms 17784 KB Output is correct
50 Correct 21 ms 17528 KB Output is correct
51 Correct 21 ms 17528 KB Output is correct
52 Correct 22 ms 17656 KB Output is correct
53 Correct 22 ms 17788 KB Output is correct
54 Correct 22 ms 17784 KB Output is correct
55 Correct 30 ms 18552 KB Output is correct
56 Correct 76 ms 23544 KB Output is correct
57 Correct 131 ms 27992 KB Output is correct
58 Correct 163 ms 31308 KB Output is correct
59 Correct 216 ms 35912 KB Output is correct
60 Correct 269 ms 41056 KB Output is correct
61 Correct 308 ms 45928 KB Output is correct
62 Correct 352 ms 48616 KB Output is correct
63 Correct 423 ms 53728 KB Output is correct
64 Correct 439 ms 54884 KB Output is correct
65 Correct 183 ms 81508 KB Output is correct
66 Correct 184 ms 81560 KB Output is correct
67 Correct 194 ms 34936 KB Output is correct
68 Correct 306 ms 71772 KB Output is correct
69 Correct 366 ms 67912 KB Output is correct
70 Correct 360 ms 67932 KB Output is correct
71 Correct 457 ms 93584 KB Output is correct
72 Correct 456 ms 93604 KB Output is correct
73 Correct 391 ms 81744 KB Output is correct
74 Correct 394 ms 81692 KB Output is correct
75 Correct 391 ms 79820 KB Output is correct
76 Correct 391 ms 79916 KB Output is correct
77 Correct 408 ms 77500 KB Output is correct
78 Correct 414 ms 73416 KB Output is correct
79 Correct 375 ms 65040 KB Output is correct