-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj_1005.cpp
More file actions
52 lines (46 loc) · 1.09 KB
/
boj_1005.cpp
File metadata and controls
52 lines (46 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//<1005>번 : <ACM Craft>
#include <iostream>
#include <vector>
using namespace std;
int t, n, k, w;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> t;
while(t--) {
vector<int> adj[1001];
vector<int> order;
int cost[1001] = {};
int indeg[1001] = {};
cin >> n >> k;
for(int i = 1; i <= n; i++) {
cin >> cost[i];
}
for(int i = 0; i < k; i++) {
int x, y;
cin >> x >> y;
adj[x].push_back(y);
indeg[y]++;
}
cin >> w;
for(int i = 0; i < n; i++) {
for(int j = 1; j <= n; j++) {
if(indeg[j] == 0) {
order.push_back(j);
for(auto v : adj[j]) {
indeg[v]--;
}
indeg[j] = -1;
}
}
}
int total = 0;
for(int i = 0; i < n; i++) {
if(order[i] == w) break;
total += cost[order[i]];
}
cout << total << '\n';
}
return 0;
}