結果

問題 No.1147 土偶Ⅱ
ユーザー face4face4
提出日時 2020-08-05 19:50:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 103 ms / 500 ms
コード長 1,274 bytes
コンパイル時間 2,365 ms
コンパイル使用メモリ 76,512 KB
実行使用メモリ 39,184 KB
最終ジャッジ日時 2024-04-19 18:04:29
合計ジャッジ時間 4,262 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
37,248 KB
testcase_01 AC 50 ms
37,160 KB
testcase_02 AC 51 ms
37,248 KB
testcase_03 AC 52 ms
37,040 KB
testcase_04 AC 69 ms
38,204 KB
testcase_05 AC 52 ms
37,392 KB
testcase_06 AC 91 ms
38,588 KB
testcase_07 AC 94 ms
39,184 KB
testcase_08 AC 55 ms
37,372 KB
testcase_09 AC 89 ms
39,184 KB
testcase_10 AC 68 ms
37,948 KB
testcase_11 AC 91 ms
38,740 KB
testcase_12 AC 88 ms
38,304 KB
testcase_13 AC 60 ms
37,188 KB
testcase_14 AC 95 ms
38,780 KB
testcase_15 AC 93 ms
38,224 KB
testcase_16 AC 63 ms
37,500 KB
testcase_17 AC 52 ms
37,324 KB
testcase_18 AC 53 ms
37,180 KB
testcase_19 AC 103 ms
38,924 KB
testcase_20 AC 52 ms
37,252 KB
testcase_21 AC 51 ms
37,032 KB
testcase_22 AC 85 ms
38,476 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<<29;
            }
        }
        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++){
                for(int j = 0; j < n; j++){
                    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