File tree Expand file tree Collapse file tree 1 file changed +40
-4
lines changed Expand file tree Collapse file tree 1 file changed +40
-4
lines changed Original file line number Diff line number Diff line change 1
- // Authored by : BaaaaaaaaaaarkingDog
1
+ // Authored by : scsc3204
2
2
// Co-authored by : -
3
- // http://boj.kr/****************
3
+ // http://boj.kr/ddd8214a903148c381289d51e1027039
4
4
#include < bits/stdc++.h>
5
5
using namespace std ;
6
6
7
- int main (void ){
7
+ int solve () {
8
+ int n, k; cin >> n >> k;
9
+ vector<int > adj[n + 2 ];
10
+ int cost[n + 2 ] = {};
11
+ int tot[n + 2 ] = {};
12
+ int ind[n + 2 ] = {};
13
+
14
+ for (int i = 1 ; i <= n; i++)
15
+ cin >> cost[i];
16
+
17
+ while (k--) {
18
+ int u, v;
19
+ cin >> u >> v;
20
+ ind[v]++;
21
+ adj[u].push_back (v);
22
+ }
23
+
24
+ int w; cin >> w;
25
+ queue<int > q;
26
+ for (int i = 1 ; i <= n; i++)
27
+ if (!ind[i]) q.push (i);
28
+
29
+ while (!q.empty ()) {
30
+ int cur = q.front (); q.pop ();
31
+ for (int nxt : adj[cur]) {
32
+ tot[nxt] = max (tot[nxt], cost[cur] + tot[cur]);
33
+ ind[nxt]--;
34
+ if (!ind[nxt]) q.push (nxt);
35
+ }
36
+ }
37
+ return tot[w] + cost[w];
38
+ }
39
+
40
+ int main () {
8
41
ios::sync_with_stdio (0 );
9
42
cin.tie (0 );
10
-
43
49E8
+
44
+ int t; cin >> t;
45
+ while (t--)
46
+ cout << solve () << ' \n ' ;
11
47
}
You can’t perform that action at this time.
0 commit comments