結果

問題 No.488 四角関係
ユーザー data9824data9824
提出日時 2017-02-26 15:04:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 1,060 bytes
コンパイル時間 739 ms
コンパイル使用メモリ 51,652 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-02 09:55:44
合計ジャッジ時間 1,968 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;

int n, m;
bool links[51][51] = { false };
int nodes[4];

int count(int node, int remaining) {
    nodes[remaining] = node;
    if (remaining == 0) {
        bool closed = true;
        for (int i = 0; i < 4; ++i) {
            int linkCount = 0;
            for (int k = 0; k < 4; ++k) {
                if (links[nodes[i]][nodes[k]]) {
                    ++linkCount;
                }
            }
            if (linkCount != 2) {
                closed = false;
                break;
            }
        }
        return closed ? 1 : 0;
    }
    int result = 0;
    for (int i = node + 1; i < n; ++i) {
        result += count(i, remaining - 1);
    }
    return result;
}

int main(int argc, const char * argv[]) {
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        links[a][b] = true;
        links[b][a] = true;
    }
    int result = 0;
    for (int i = 0; i < n; ++i) {
        result += count(i, 3);
    }
    cout << result << endl;
    return 0;
}
0