-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCG_46.java
More file actions
64 lines (51 loc) · 1.84 KB
/
Copy pathCG_46.java
File metadata and controls
64 lines (51 loc) · 1.84 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
53
54
55
56
57
58
59
60
61
62
63
64
import java.util.Scanner;
import java.io.FileInputStream;
class CG_46 { // 할인권
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);
}
}
}