結果

問題 No.629 グラフの中に眠る門松列
ユーザー hogeover30hogeover30
提出日時 2018-01-18 13:54:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 797 bytes
コンパイル時間 2,021 ms
コンパイル使用メモリ 204,808 KB
実行使用メモリ 814,460 KB
最終ジャッジ日時 2023-08-25 23:16:14
合計ジャッジ時間 5,071 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,268 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 MLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, m; cin>>n>>m;
    vector<int> a(n);
    for(auto& e: a) cin>>e;

    vector<vector<int>> g(n);
    while (m--) {
        int u, v; cin>>u>>v;
        --u, --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    auto is_kadomatsu=[&](int i, int j, int k)
    {
        return (a[i]<a[j] and a[j]>a[k] or a[i]>a[j] and a[j]<a[k]) and a[i]!=a[k];
    };

    function<bool(int, int, int)> dfs=[&](int i, int j, int k)
    {
        if (k>=0 && is_kadomatsu(i, j, k)) return true;
        for(int v: g[i])
            if (v!=j and dfs(v, i, j)) return true;
        return false;
    };

    for(int i=0; i<n; ++i) {
        if (dfs(i, -1, -1))
            return cout<<"YES"<<endl, 0;
    }
    cout<<"NO"<<endl;
}
0