Task: | Chain Reaction |
Sender: | aalto2024m_001 |
Submission time: | 2024-11-25 17:49:30 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | TIME LIMIT EXCEEDED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | ACCEPTED | 0.00 s | details |
#4 | ACCEPTED | 0.00 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | ACCEPTED | 0.00 s | details |
#7 | ACCEPTED | 0.00 s | details |
#8 | ACCEPTED | 0.00 s | details |
#9 | ACCEPTED | 0.00 s | details |
#10 | ACCEPTED | 0.00 s | details |
#11 | ACCEPTED | 0.00 s | details |
#12 | ACCEPTED | 0.00 s | details |
#13 | TIME LIMIT EXCEEDED | -- | details |
#14 | TIME LIMIT EXCEEDED | -- | details |
#15 | TIME LIMIT EXCEEDED | -- | details |
#16 | TIME LIMIT EXCEEDED | -- | details |
#17 | TIME LIMIT EXCEEDED | -- | details |
#18 | ACCEPTED | 0.00 s | details |
#19 | ACCEPTED | 0.00 s | details |
#20 | ACCEPTED | 0.00 s | details |
#21 | ACCEPTED | 0.00 s | details |
#22 | ACCEPTED | 0.00 s | details |
#23 | TIME LIMIT EXCEEDED | -- | details |
#24 | TIME LIMIT EXCEEDED | -- | details |
#25 | TIME LIMIT EXCEEDED | -- | details |
#26 | TIME LIMIT EXCEEDED | -- | details |
#27 | TIME LIMIT EXCEEDED | -- | details |
#28 | TIME LIMIT EXCEEDED | -- | details |
#29 | TIME LIMIT EXCEEDED | -- | details |
#30 | TIME LIMIT EXCEEDED | -- | details |
#31 | TIME LIMIT EXCEEDED | -- | details |
#32 | TIME LIMIT EXCEEDED | -- | details |
Code
#include <iostream> #include <vector> #include <algorithm> using namespace std; vector<vector<int>> tree; vector<int> neutrones; vector<int> protones; int max_charge = 0; void dfs(int node, int parent, int charge) { max_charge = max(max_charge, charge); for (int neighbor : tree[node]) { if (neighbor != parent) { int charge_with_neutrones = charge + (neutrones[neighbor] - neutrones[node]); int charge_with_protones = charge + (protones[neighbor] - protones[node]); dfs(neighbor, node, charge_with_neutrones); dfs(neighbor, node, charge_with_protones); } } } int main() { int n, s; cin >> n >> s; s--; neutrones.resize(n); protones.resize(n); tree.resize(n); for (int i = 0; i < n; i++) { cin >> neutrones[i]; } for (int i = 0; i < n; i++) { cin >> protones[i]; } for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; u--; v--; tree[u].push_back(v); tree[v].push_back(u); } dfs(s, -1, 1); cout << max_charge << endl; return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
5 1
4 2 1 1 1 5 2 1 5 4 1 2 1 3 ... |
correct output |
---|
2 |
user output |
---|
2 |
Test 2
Verdict: ACCEPTED
input |
---|
4 1
4 2 2 1 1 1 1 1 1 2 2 3 ... |
correct output |
---|
1 |
user output |
---|
1 |
Test 3
Verdict: ACCEPTED
input |
---|
10 8
7 2 10 4 5 9 1 2 3 1 9 8 6 6 4 6 10 1 7 8 4 5 10 3 ... |
correct output |
---|
19 |
user output |
---|
19 |
Test 4
Verdict: ACCEPTED
input |
---|
10 1
8 8 6 8 1 9 2 2 7 7 9 6 5 9 2 5 6 5 5 8 1 6 6 7 ... |
correct output |
---|
9 |
user output |
---|
9 |
Test 5
Verdict: ACCEPTED
input |
---|
10 1
4 1 4 1 4 6 1 1 4 5 5 9 3 9 8 8 10 8 7 10 3 1 1 9 ... |
correct output |
---|
11 |
user output |
---|
11 |
Test 6
Verdict: ACCEPTED
input |
---|
10 9
9 9 3 3 3 4 1 7 1 9 3 9 10 5 6 6 9 6 9 6 3 8 8 6 ... |
correct output |
---|
19 |
user output |
---|
19 |
Test 7
Verdict: ACCEPTED
input |
---|
10 1
3 4 2 2 2 10 1 5 10 3 10 8 7 6 2 10 1 6 1 3 2 3 10 4 ... |
correct output |
---|
15 |
user output |
---|
15 |
Test 8
Verdict: ACCEPTED
input |
---|
10 10
80 58 90 31 79 35 10 75 83 70 48 2 25 73 99 7 53 79 36 89 9 4 7 9 ... |
correct output |
---|
54 |
user output |
---|
54 |
Test 9
Verdict: ACCEPTED
input |
---|
10 9
50 84 12 34 86 71 73 78 6 62 29 97 88 56 84 94 94 98 36 96 5 10 3 1 ... |
correct output |
---|
149 |
user output |
---|
149 |
Test 10
Verdict: ACCEPTED
input |
---|
10 5
7 66 89 87 27 80 2 11 29 3 98 7 52 66 21 2 26 19 96 31 4 6 1 10 ... |
correct output |
---|
226 |
user output |
---|
226 |
Test 11
Verdict: ACCEPTED
input |
---|
10 3
91 13 67 44 6 83 21 8 23 14 54 19 30 26 60 73 22 90 36 84 5 10 4 2 ... |
correct output |
---|
151 |
user output |
---|
151 |
Test 12
Verdict: ACCEPTED
input |
---|
10 5
87 61 47 96 50 23 35 54 26 87 16 60 77 75 77 91 59 16 23 51 5 1 10 8 ... |
correct output |
---|
175 |
user output |
---|
175 |
Test 13
Verdict: TIME LIMIT EXCEEDED
input |
---|
97304 87743
876894525 229121152 393060078 ... |
correct output |
---|
131459576065 |
user output |
---|
(empty) |
Test 14
Verdict: TIME LIMIT EXCEEDED
input |
---|
74779 53246
763040787 482885163 932005790 ... |
correct output |
---|
155373737827 |
user output |
---|
(empty) |
Test 15
Verdict: TIME LIMIT EXCEEDED
input |
---|
89537 85789
432185633 432110306 240073971 ... |
correct output |
---|
255801753825 |
user output |
---|
(empty) |
Test 16
Verdict: TIME LIMIT EXCEEDED
input |
---|
99086 49261
283011093 775415197 945248913 ... |
correct output |
---|
162897193427 |
user output |
---|
(empty) |
Test 17
Verdict: TIME LIMIT EXCEEDED
input |
---|
95142 68716
163121171 100246843 163249744 ... |
correct output |
---|
181966887510 |
user output |
---|
(empty) |
Test 18
Verdict: ACCEPTED
input |
---|
19 3
49 73 32 44 84 29 9 76 77 36 9... |
correct output |
---|
147 |
user output |
---|
147 |
Test 19
Verdict: ACCEPTED
input |
---|
19 6
68 94 70 46 91 47 67 100 62 23... |
correct output |
---|
244 |
user output |
---|
244 |
Test 20
Verdict: ACCEPTED
input |
---|
18 3
90 65 90 80 41 5 95 17 53 7 29... |
correct output |
---|
127 |
user output |
---|
127 |
Test 21
Verdict: ACCEPTED
input |
---|
16 1
48 91 87 2 16 39 92 26 1 68 78... |
correct output |
---|
224 |
user output |
---|
224 |
Test 22
Verdict: ACCEPTED
input |
---|
15 2
11 1 37 1 8 20 24 59 42 52 91 ... |
correct output |
---|
219 |
user output |
---|
219 |
Test 23
Verdict: TIME LIMIT EXCEEDED
input |
---|
94171 47986
552466372 215830212 408722990 ... |
correct output |
---|
150760767335 |
user output |
---|
(empty) |
Test 24
Verdict: TIME LIMIT EXCEEDED
input |
---|
94221 86537
45774448 992088337 309200563 7... |
correct output |
---|
105016024608 |
user output |
---|
(empty) |
Test 25
Verdict: TIME LIMIT EXCEEDED
input |
---|
96867 68461
39428919 749383323 481367036 5... |
correct output |
---|
219609902823 |
user output |
---|
(empty) |
Test 26
Verdict: TIME LIMIT EXCEEDED
input |
---|
96077 83268
95064821 23000135 276477667 48... |
correct output |
---|
140845793522 |
user output |
---|
(empty) |
Test 27
Verdict: TIME LIMIT EXCEEDED
input |
---|
99950 74867
864529930 269063846 767129921 ... |
correct output |
---|
217758011647 |
user output |
---|
(empty) |
Test 28
Verdict: TIME LIMIT EXCEEDED
input |
---|
97182 41080
671075894 704355936 662862756 ... |
correct output |
---|
167687874177 |
user output |
---|
(empty) |
Test 29
Verdict: TIME LIMIT EXCEEDED
input |
---|
96113 18731
554071104 111523361 276689875 ... |
correct output |
---|
207695993751 |
user output |
---|
(empty) |
Test 30
Verdict: TIME LIMIT EXCEEDED
input |
---|
92311 6858
440850686 890390689 572816739 ... |
correct output |
---|
150986466317 |
user output |
---|
(empty) |
Test 31
Verdict: TIME LIMIT EXCEEDED
input |
---|
99999 25726
949775640 24729596 158203669 2... |
correct output |
---|
125772383324 |
user output |
---|
(empty) |
Test 32
Verdict: TIME LIMIT EXCEEDED
input |
---|
97857 32129
20264277 670255203 316861628 1... |
correct output |
---|
182392362837 |
user output |
---|
(empty) |