結果

問題 No.488 四角関係
ユーザー htensaihtensai
提出日時 2019-12-19 14:29:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 108 ms / 5,000 ms
コード長 1,703 bytes
コンパイル時間 2,216 ms
コンパイル使用メモリ 74,844 KB
実行使用メモリ 52,628 KB
最終ジャッジ日時 2023-09-21 06:44:54
合計ジャッジ時間 5,080 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
50,560 KB
testcase_01 AC 91 ms
51,964 KB
testcase_02 AC 82 ms
52,084 KB
testcase_03 AC 64 ms
50,872 KB
testcase_04 AC 82 ms
51,288 KB
testcase_05 AC 95 ms
52,032 KB
testcase_06 AC 63 ms
50,932 KB
testcase_07 AC 108 ms
52,628 KB
testcase_08 AC 102 ms
52,260 KB
testcase_09 AC 44 ms
49,232 KB
testcase_10 AC 58 ms
49,940 KB
testcase_11 AC 48 ms
49,240 KB
testcase_12 AC 64 ms
50,320 KB
testcase_13 AC 60 ms
50,296 KB
testcase_14 AC 48 ms
49,208 KB
testcase_15 AC 46 ms
49,180 KB
testcase_16 AC 44 ms
49,612 KB
testcase_17 AC 44 ms
49,360 KB
testcase_18 AC 45 ms
49,444 KB
testcase_19 AC 48 ms
49,376 KB
testcase_20 AC 45 ms
49,620 KB
testcase_21 AC 46 ms
49,340 KB
testcase_22 AC 44 ms
49,512 KB
testcase_23 AC 46 ms
49,188 KB
testcase_24 AC 47 ms
49,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    static HashSet<Integer>[] graph;
    static int n;
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] first = br.readLine().split(" ", 2);
        int n = Integer.parseInt(first[0]);
        int m = Integer.parseInt(first[1]);
        graph = new HashSet[n];
        for (int i = 0; i < n; i++) {
            graph[i] = new HashSet<Integer>();
        }
        for (int i = 0; i < m; i++) {
            String[] line = br.readLine().split(" ", 2);
            int a = Integer.parseInt(line[0]);
            int b = Integer.parseInt(line[1]);
            graph[a].add(b);
            graph[b].add(a);
        }
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (graph[i].size() < 2) {
                continue;
            }
            for (int x : graph[i]) {
                for (int y : graph[i]) {
                    if (x >= y) {
                        continue;
                    }
                    if (graph[x].contains(y)) {
                        continue;
                    }
                    count += getCount(x, y, i);
                }
            }
        }
        System.out.println(count / 4);
    }
    
    static int getCount(int a, int b, int except) {
        int count = 0;
        for (int i = 0; i < graph.length; i++) {
            if (i == except) {
                continue;
            }
            if (graph[i].contains(a) && graph[i].contains(b) && !graph[i].contains(except)) {
                count++;
            }
        }
        return count;
    }
}
0