結果

問題 No.629 グラフの中に眠る門松列
ユーザー hogeover30
提出日時 2018-01-18 14:22:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 667 bytes
コンパイル時間 2,266 ms
コンパイル使用メモリ 197,836 KB
最終ジャッジ日時 2025-01-05 07:40:40
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5 WA * 1
other AC * 27 WA * 9
権限があれば一括ダウンロードができます

ソースコード

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<pair<int, int>> edges;
    while (m--) {
        int u, v; cin>>u>>v;
        edges.emplace_back(--u, --v);
    }

    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];
    };

    for(auto& [u, v]: edges) {
        for(auto& [x, y]: edges) {
            if (v==x and is_kadomatsu(u, v, y)) return cout<<"YES"<<endl, 0;
            if (v==y and is_kadomatsu(u, v, x)) return cout<<"YES"<<endl, 0;
        }
    }
    cout<<"NO"<<endl;
}
0