結果

問題 No.408 五輪ピック
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-10-18 21:47:24
言語 D
(dmd 2.109.1)
結果
TLE  
実行時間 -
コード長 1,146 bytes
コンパイル時間 964 ms
コンパイル使用メモリ 96,336 KB
実行使用メモリ 12,664 KB
最終ジャッジ日時 2024-06-12 04:36:37
合計ジャッジ時間 8,085 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24 TLE * 1 -- * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio;
import std.algorithm;
import std.typecons;
import std.string;
import std.array;
import std.conv;
import std.container;

void main() {
    int N, M;
    scanf("%d %d\n", &N, &M);
    alias E = Tuple!(int, int);
    bool[E] es;
    E[] es1;
    int[] zero_n;
    foreach (i; 0 .. M) {
        int a, b;
        scanf("%d %d\n", &a, &b);
        a--; b--;
        if (a > b) swap(a, b);
        if (a == 0) zero_n ~= b;
        else es1 ~= E(a, b);
        es[E(a, b)] = true;
    }

    bool f(int a, int b) {
        if (a > b) swap(a, b);
        return E(a, b) in es ? true : false;
    }


    foreach (e; es1) {
        bool a = false, b = false;
        int c = 0;
        foreach (i; zero_n) {
            if (i == e[0] || i == e[1]) continue;
            bool flag = false;
            if (f(e[0], i)) {
                a = true;
                flag =true;
            }
            if (f(e[1], i)) {
                b = true;
                flag = true;
            }
            c += flag;
        }
        if (c >= 2 && a && b) {
            writeln("YES");
            return;
        }
    }
    writeln("NO");

}
0