Skip to content

Commit f522faa

Browse files
authored
[20250225] BOJ / G3 / 양 구출 작전 / 권혁준
1 parent f1e1b6f commit f522faa

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)