結果

問題 No.629 グラフの中に眠る門松列
ユーザー kappybarkappybar
提出日時 2020-05-09 22:38:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 4,000 ms
コード長 1,304 bytes
コンパイル時間 2,014 ms
コンパイル使用メモリ 171,556 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 09:36:11
合計ジャッジ時間 5,746 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
int n = 1005,m;
vector<vector<int>> graph(n,vector<int>());
vector<int> a(n);

bool iskadomatu(vector<int> v){
    if(v[0] == v[1] || v[1] == v[2] || v[0] == v[2]) return false;
    if(v[1] > v[0] && v[1] > v[2]) return true;
    if(v[1] < v[0] && v[1] < v[2]) return true;
    return false;
}

bool dfs(int i,vector<int> v,int p=-1){
    if((int)(v.size()) == 3){
        if(iskadomatu(v)) return true;
        else return false;
    }

    bool res = false;
    for(int c:graph[i]){
        if(c==p) continue;
        v.push_back(a[c]);
        res = res || dfs(c,v,i);
        v.pop_back();
    }

    return res;
}

int main(){
    cin >> n >> m;
    rep(i,n) cin >> a[i];
    rep(i,m){
        int u,v;
        cin >> u >> v;
        --u;--v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    vector<int> v;
    rep(i,n){
        v.push_back(a[i]);
        if(dfs(i,v)){
            cout << "YES" << endl;
            return 0;
        }
        v.pop_back();
    }
    cout << "NO" << endl;
    return 0;
}
0