結果

問題 No.488 四角関係
ユーザー jp_stejp_ste
提出日時 2017-05-14 09:34:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,556 ms / 5,000 ms
コード長 1,780 bytes
コンパイル時間 3,176 ms
コンパイル使用メモリ 74,284 KB
実行使用メモリ 63,248 KB
最終ジャッジ日時 2023-10-14 10:53:36
合計ジャッジ時間 10,503 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 180 ms
58,012 KB
testcase_01 AC 511 ms
63,248 KB
testcase_02 AC 337 ms
59,368 KB
testcase_03 AC 285 ms
58,876 KB
testcase_04 AC 315 ms
58,936 KB
testcase_05 AC 514 ms
61,388 KB
testcase_06 AC 192 ms
57,732 KB
testcase_07 AC 1,556 ms
61,904 KB
testcase_08 AC 318 ms
59,688 KB
testcase_09 AC 119 ms
55,764 KB
testcase_10 AC 185 ms
58,040 KB
testcase_11 AC 134 ms
55,836 KB
testcase_12 AC 286 ms
58,760 KB
testcase_13 AC 201 ms
57,656 KB
testcase_14 AC 138 ms
55,772 KB
testcase_15 AC 125 ms
55,720 KB
testcase_16 AC 123 ms
55,884 KB
testcase_17 AC 126 ms
55,832 KB
testcase_18 AC 130 ms
55,592 KB
testcase_19 AC 128 ms
55,896 KB
testcase_20 AC 125 ms
56,364 KB
testcase_21 AC 121 ms
56,564 KB
testcase_22 AC 125 ms
55,808 KB
testcase_23 AC 123 ms
55,812 KB
testcase_24 AC 133 ms
55,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int n;
    static int m;
    static boolean list[][];
    static ArrayList<int[]> al = new ArrayList<int[]>();
    
    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(al.size());
    }
    
    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]])) {
                    int copy[] = con.clone();
                    Arrays.sort(copy);
                    boolean flag = true;
                    for (int[] i : al) {
                        if (Arrays.equals(i, copy)) {
                            flag = false;
                            break;
                        }
                    }
                    if(flag) {
                        al.add(copy);
                    }
                }
            }
            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