結果

問題 No.488 四角関係
ユーザー tenten
提出日時 2020-12-18 14:19:39
言語 Java
(openjdk 27.0.1.0.3 + ACL)
コンパイル:
javac -J-Duser.language=en -encoding UTF8 -cp /opt/aclib/ac_library.jar _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true -cp .:/opt/aclib/ac_library.jar _class_
結果
AC  
実行時間 269 ms / 5,000 ms
+ 302µs
コード長 1,396 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,500 ms
コンパイル使用メモリ 94,076 KB
実行使用メモリ 52,016 KB
最終ジャッジ日時 2026-11-06 00:56:08
合計ジャッジ時間 8,732 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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