結果

問題 No.488 四角関係
ユーザー tentententen
提出日時 2020-12-18 14:19:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 231 ms / 5,000 ms
コード長 1,396 bytes
コンパイル時間 4,091 ms
コンパイル使用メモリ 79,364 KB
実行使用メモリ 60,328 KB
最終ジャッジ日時 2023-10-21 08:06:43
合計ジャッジ時間 6,855 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
57,432 KB
testcase_01 AC 191 ms
57,464 KB
testcase_02 AC 176 ms
57,648 KB
testcase_03 AC 148 ms
57,320 KB
testcase_04 AC 167 ms
57,364 KB
testcase_05 AC 199 ms
57,856 KB
testcase_06 AC 151 ms
57,520 KB
testcase_07 AC 231 ms
58,652 KB
testcase_08 AC 185 ms
60,328 KB
testcase_09 AC 114 ms
56,944 KB
testcase_10 AC 136 ms
57,472 KB
testcase_11 AC 126 ms
57,572 KB
testcase_12 AC 143 ms
57,380 KB
testcase_13 AC 139 ms
57,344 KB
testcase_14 AC 128 ms
57,328 KB
testcase_15 AC 127 ms
57,080 KB
testcase_16 AC 116 ms
57,220 KB
testcase_17 AC 110 ms
56,076 KB
testcase_18 AC 132 ms
57,152 KB
testcase_19 AC 122 ms
57,492 KB
testcase_20 AC 116 ms
57,232 KB
testcase_21 AC 114 ms
57,284 KB
testcase_22 AC 115 ms
54,972 KB
testcase_23 AC 101 ms
55,508 KB
testcase_24 AC 116 ms
57,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
        ArrayList<ArrayList<Integer>> graph = new ArrayList<>();
        ArrayList<HashSet<Integer>> exist = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            graph.add(new ArrayList<>());
            exist.add(new HashSet<>());
        }
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            graph.get(a).add(b);
            graph.get(b).add(a);
            exist.get(a).add(b);
            exist.get(b).add(a);
        }
        int ans = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                if (exist.get(i).contains(j)) {
                    continue;
                }
                for (int a = 0; a < graph.get(i).size() - 1; a++) {
                    for (int b = a + 1; b < graph.get(i).size(); b++) {
                        if (exist.get(j).contains(graph.get(i).get(a)) && exist.get(j).contains(graph.get(i).get(b)) && !exist.get(graph.get(i).get(a)).contains(graph.get(i).get(b))) {
                            ans++;
                        }
                    }
                }
            }
        }
        System.out.println(ans / 2);
    }
}
0