結果
| 問題 | No.1147 土偶Ⅱ |
| ユーザー |
tenten
|
| 提出日時 | 2020-08-17 18:55:03 |
| 言語 | Java (openjdk 25.0.1) |
| 結果 |
AC
|
| 実行時間 | 229 ms / 500 ms |
| コード長 | 1,188 bytes |
| 記録 | |
| コンパイル時間 | 2,561 ms |
| コンパイル使用メモリ | 77,344 KB |
| 実行使用メモリ | 44,080 KB |
| 最終ジャッジ日時 | 2024-10-11 11:13:45 |
| 合計ジャッジ時間 | 7,306 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int[][] costs = new int[n][n];
for (int i = 0; i < n; i++) {
Arrays.fill(costs[i], Integer.MAX_VALUE / 10);
costs[i][i] = 0;
}
for (int i = 0; i < m; i++) {
int a = sc.nextInt() - 1;
int b = sc.nextInt() - 1;
costs[a][b] = 1;
costs[b][a] = 1;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
costs[j][k] = Math.min(costs[j][k], costs[j][i] + costs[i][k]);
}
}
}
int count = 0;
for (int i = 0; i < n - 2; i++) {
for (int j = i + 1; j < n - 1; j++) {
for (int k = j + 1; k < n; k++) {
if (costs[i][j] != 2 && costs[j][k] != 2 && costs[i][k] != 2) {
count++;
}
}
}
}
System.out.println(count);
}
}
tenten