結果

問題 No.1147 土偶Ⅱ
ユーザー face4face4
提出日時 2020-08-05 19:46:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 109 ms / 500 ms
コード長 1,348 bytes
コンパイル時間 2,185 ms
コンパイル使用メモリ 77,296 KB
実行使用メモリ 39,464 KB
最終ジャッジ日時 2024-04-19 18:04:14
合計ジャッジ時間 4,522 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
36,832 KB
testcase_01 AC 50 ms
36,740 KB
testcase_02 AC 48 ms
36,580 KB
testcase_03 AC 48 ms
36,808 KB
testcase_04 AC 65 ms
37,932 KB
testcase_05 AC 49 ms
36,588 KB
testcase_06 AC 103 ms
39,016 KB
testcase_07 AC 99 ms
38,876 KB
testcase_08 AC 51 ms
37,028 KB
testcase_09 AC 84 ms
38,252 KB
testcase_10 AC 66 ms
37,760 KB
testcase_11 AC 88 ms
38,784 KB
testcase_12 AC 73 ms
37,864 KB
testcase_13 AC 55 ms
37,164 KB
testcase_14 AC 90 ms
38,616 KB
testcase_15 AC 79 ms
38,212 KB
testcase_16 AC 59 ms
37,108 KB
testcase_17 AC 51 ms
37,072 KB
testcase_18 AC 52 ms
37,028 KB
testcase_19 AC 109 ms
39,464 KB
testcase_20 AC 50 ms
36,716 KB
testcase_21 AC 48 ms
36,584 KB
testcase_22 AC 83 ms
38,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");
        int n = Integer.parseInt(line[0]);
        int m = Integer.parseInt(line[1]);
        int x[][] = new int[n][n];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                x[i][j] = i==j ? 0 : 1<<30;
            }
        }
        while(m-- > 0){
            line = br.readLine().split(" ");
            int a = Integer.parseInt(line[0])-1;
            int b = Integer.parseInt(line[1])-1;
            x[a][b] = x[b][a] = 1;
        }
        for(int k = 0; k < n; k++){
            for(int i = 0; i < n; i++){
                if(x[i][k] == 1<<30)    continue;
                for(int j = 0; j < n; j++){
                    if(x[k][j] != 1<<30)    x[i][j] = Math.min(x[i][j], x[i][k]+x[k][j]);
                }
            }
        }
        int ans = 0;
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                if(x[i][j] == 2) continue;
                for(int k = j+1; k < n; k++){
                    if(x[i][k] != 2 && x[j][k] != 2)    ans++;
                }
            }
        }
        System.out.println(ans);
    }
}
0