We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f1e1b6f commit f522faaCopy full SHA for f522faa
khj20006/202502/25 BOJ G3 양 구출 작전.md
@@ -0,0 +1,35 @@
1
+```cpp
2
+
3
+#include <iostream>
4
+#include <vector>
5
+#include <algorithm>
6
+using namespace std;
7
+using ll = long long;
8
9
+int N;
10
+vector<vector<int>> V(123457);
11
+ll C[123457]{};
12
13
+ll dfs(int n) {
14
+ ll res = C[n];
15
+ for (int i : V[n]) res += dfs(i);
16
+ return max(res, 0LL);
17
+}
18
19
+int main()
20
+{
21
+ cin.tie(0)->sync_with_stdio(0);
22
23
+ cin >> N;
24
+ for (int i = 2, a, b; i <= N; i++) {
25
+ char o;
26
+ cin >> o >> a >> b;
27
+ V[b].push_back(i);
28
+ C[i] = a * (o == 'S' ? 1 : -1);
29
+ }
30
31
+ cout << dfs(1);
32
33
34
35
+```
0 commit comments