이전 문제에서 틀을 바꾸지 않고 코드를 짰더니 오류가 나길래 알고리즘이 틀린지 알고 엄청 들여다 봤는데...
결과 출력하는 Case#이 #testcase로 되어있어서 그랬던 거였다.
이런 삽질 정말 다신 하고 싶지 않고.. 내 시간...
결과 출력하는 Case#이 #testcase로 되어있어서 그랬던 거였다.
이런 삽질 정말 다신 하고 싶지 않고.. 내 시간...
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 53 54 55 56 57 58 59 60 61 62 63 64 | import java.util.Scanner; import java.io.FileInputStream; class Solution { public static void main(String args[]) throws Exception { // Scanner sc = new Scanner(new FileInputStream("sample_input.txt")); Scanner sc = new Scanner(System.in); int T; int test_case; T = sc.nextInt(); for (test_case = 1; test_case <= T; test_case++) { int n = sc.nextInt(); int m = sc.nextInt(); int k = sc.nextInt(); int unknown = 9999; int sale_ticket = 0; int arr[][] = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) arr[i][j] = 0; else arr[i][j] = unknown; } } // 배열 초기화 for (int i = 0; i < m; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; arr[a][b] = sc.nextInt(); arr[b][a] = arr[a][b]; } // 배열에 값 넣기 for (int pass = 0; pass < n; pass++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (arr[i][j] > arr[i][pass] + arr[pass][j]) { arr[i][j] = arr[i][pass] + arr[pass][j]; } } } } int p = sc.nextInt(); for (int i = 0; i < p; i++) { int s = sc.nextInt() - 1; int e = sc.nextInt() - 1; if (arr[s][e] > k) sale_ticket++; } System.out.println("Case #" + test_case); System.out.println(sale_ticket); } } } | cs |
'공부 > 알고리즘문제' 카테고리의 다른 글
백준 1012 유기농 배추 (0) | 2017.04.13 |
---|---|
백준 13458 시험 감독 (0) | 2017.04.12 |
백준 14499 주사위 굴리기 (0) | 2017.04.12 |
코드그라운드 시험 공부 (0) | 2017.04.11 |
코드그라운드 숫자 골라내기 (0) | 2017.04.11 |