結果

問題 No.488 四角関係
ユーザー jp_stejp_ste
提出日時 2017-05-14 10:00:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 317 ms / 5,000 ms
コード長 1,333 bytes
コンパイル時間 1,957 ms
コンパイル使用メモリ 74,096 KB
実行使用メモリ 59,580 KB
最終ジャッジ日時 2023-10-14 10:53:53
合計ジャッジ時間 7,061 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 156 ms
56,140 KB
testcase_01 AC 189 ms
56,736 KB
testcase_02 AC 178 ms
56,696 KB
testcase_03 AC 169 ms
55,852 KB
testcase_04 AC 186 ms
56,340 KB
testcase_05 AC 199 ms
54,988 KB
testcase_06 AC 174 ms
56,248 KB
testcase_07 AC 239 ms
56,720 KB
testcase_08 AC 317 ms
59,580 KB
testcase_09 AC 121 ms
56,024 KB
testcase_10 AC 158 ms
56,236 KB
testcase_11 AC 129 ms
55,936 KB
testcase_12 AC 169 ms
56,464 KB
testcase_13 AC 160 ms
56,260 KB
testcase_14 AC 131 ms
55,960 KB
testcase_15 AC 122 ms
55,732 KB
testcase_16 AC 123 ms
55,816 KB
testcase_17 AC 128 ms
56,008 KB
testcase_18 AC 128 ms
55,520 KB
testcase_19 AC 136 ms
55,672 KB
testcase_20 AC 124 ms
55,656 KB
testcase_21 AC 121 ms
55,680 KB
testcase_22 AC 123 ms
53,696 KB
testcase_23 AC 122 ms
55,372 KB
testcase_24 AC 127 ms
55,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int n;
    static int m;
    static boolean list[][];
    static int ans = 0;
    
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        n = scan.nextInt();
        m = scan.nextInt();
        list = new boolean[n][n];
        for(int i=0; i<m; i++) {
            int left = scan.nextInt();
            int right = scan.nextInt();
            list[left][right] = true;
            list[right][left] = true;
        }
        for(int i=0; i<n; i++) {
            int connect[] = {i, -1, -1, -1};
            solve(connect, 0);
        }
        System.out.println(ans/8);
    }
    
    static void solve(int con[], int index) {
        int left = con[index];
        
        if(index == 3) {
            int right = con[0];
            if(list[left][right]) {
                if((!list[con[0]][con[2]]) && (!list[con[1]][con[3]])) {
                    ans++;
                }
            }
            return;    
        }
        
        for(int right=0; right<n; right++) {
            if(index > 0) {
                if(right == con[index-1]) continue;
            }
            if(list[left][right]) {
                con[index+1] = right;
                solve(con, index+1);
            }
        }
    }
}
0