File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class boj2056 {
6+ static BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
7+ static StringTokenizer st;
8+ static void nextLine () throws Exception {st = new StringTokenizer (br .readLine ());}
9+ static int nextInt() {return Integer . parseInt(st. nextToken());}
10+
11+ public static void main(String [] args) throws Exception {
12+ nextLine();
13+ int N = nextInt();
14+ int [] time = new int [N + 1 ];
15+ int [] degree = new int [N + 1 ];
16+ int answer = 0 ;
17+ ArrayList<ArrayList<Integer > > work = new ArrayList<> ();
18+ for (int i = 0 ; i < N + 1 ; i++ ) work. add(new ArrayList<> ());
19+ for (int i = 1 ; i <= N ; i++ ) {
20+ nextLine();
21+ time[i] = nextInt();
22+ int M = nextInt();
23+ for (int j = 0 ; j < M ; j++ ) {
24+ int num = nextInt();
25+ work. get(num). add(i);
26+ degree[i]++ ;
27+ }
28+ }
29+ // 위상 정렬
30+ Queue<Integer > q = new LinkedList<> ();
31+ int [] result = new int [N + 1 ];
32+ for (int i = 1 ; i <= N ; i++ ) {
33+ result[i] = time[i];
34+ if (degree[i] == 0 ) q. add(i);
35+ }
36+
37+ while (! q. isEmpty()) {
38+ int cur = q. poll();
39+ for (int next : work. get(cur)) {
40+ degree[next]-- ;
41+ result[next] = Math . max(result[next], result[cur] + time[next]);
42+ if (degree[next] == 0 ) q. add(next);
43+ }
44+ }
45+
46+ for (int i = 0 ; i <= N ; i++ ) answer = Math . max(answer, result[i]);
47+ System . out. println(answer);
48+ }
49+ }
50+ ```
You can’t perform that action at this time.
0 commit comments