public class Bae1005_2 { static int N ; static int W ; static int D[] ; static boolean line[][] ; static int dp [ ]; public static void main(String[] args) throws Exception{
Scanner sc = new Scanner(new FileInputStream("input.txt")); //Scanner sc = new Scanner(System.in) ; int T =sc.nextInt() ;
for(int t = 0 ; t < T ; t++){
N = sc.nextInt() ; W = sc.nextInt() ;
D = new int [N+1] ; line = new boolean [N+1][N+1] ; dp = new int [N+1] ; for(int x = 1 ; x <= N ; x++) D[x] = sc.nextInt() ; dp [1] = D[1] ; for(int x = 0 ; x < W ;x++) { int s = sc.nextInt() ; int e = sc.nextInt() ; line[s][e] = true ; } int target = sc.nextInt() ;
jinsub8682 3년 전
import java.io.FileInputStream;
import java.util.Scanner;
public class Bae1005_2 {
static int N ;
static int W ;
static int D[] ;
static boolean line[][] ;
static int dp [ ];
public static void main(String[] args) throws Exception{
Scanner sc = new Scanner(new FileInputStream("input.txt"));
//Scanner sc = new Scanner(System.in) ;
int T =sc.nextInt() ;
for(int t = 0 ; t < T ; t++){
N = sc.nextInt() ;
W = sc.nextInt() ;
D = new int [N+1] ;
line = new boolean [N+1][N+1] ;
dp = new int [N+1] ;
for(int x = 1 ; x <= N ; x++) D[x] = sc.nextInt() ;
dp [1] = D[1] ;
for(int x = 0 ; x < W ;x++) {
int s = sc.nextInt() ;
int e = sc.nextInt() ;
line[s][e] = true ;
}
int target = sc.nextInt() ;
for(int i = 2 ; i <=N ; i++){
dp[i] = cal(i);
}
System.out.println(dp[target]);
}
}
private static int cal(int point) {
int max = 0 ;
for(int x =1 ; x <= N ; x++){
if(line[x][point] && x!=point){
if(dp[x] > max) max = dp[x] ;
}
}
return max + D[point] ;
}
}