위상정렬 공부다가.. 결국 DP로 처리한다..
위상정렬이 어렵네..
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class BOJ2056 {
static int N;
static int[] D;
public static void main(String[] args) throws IOException {
System.setIn(new FileInputStream("res/input_boj2056.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
long Start = System.currentTimeMillis();
StringTokenizer st;
N = Integer.parseInt(br.readLine());
D = new int[N+1];
int a, b, c;
int res = 0;
for (int i = 1; i <= N ; i++) {
st = new StringTokenizer(br.readLine());
c = Integer.parseInt(st.nextToken());
a = Integer.parseInt(st.nextToken());
for (int j = 1; j <= a ; j++) {
b = Integer.parseInt(st.nextToken());
D[i] = Math.max(D[i], D[b]);
}
res = Math.max(res, D[i]+= c);
}
System.out.println(res);
}
}