結果

問題 No.629 グラフの中に眠る門松列
ユーザー rogi52
提出日時 2022-10-03 22:54:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 13 ms / 4,000 ms
コード長 785 bytes
コンパイル時間 2,134 ms
コンパイル使用メモリ 201,592 KB
最終ジャッジ日時 2025-02-07 21:01:42
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N,M; cin >> N >> M;
    vector<int> a(N);
    rep(i,N) cin >> a[i];

    vector<vector<int>> nt(N);
    rep(_,M) {
        int u,v; cin >> u >> v; u--; v--;
        nt[u].push_back(a[v]);
        nt[v].push_back(a[u]);
    }

    rep(v,N) {
        sort(nt[v].begin(), nt[v].end());
        nt[v].erase(unique(nt[v].begin(), nt[v].end()), nt[v].end());
        if(nt[v].size() >= 2u) {
            if(nt[v][1] < a[v] || a[v] < nt[v][int(nt[v].size()) - 1 - 1]) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }

    cout << "NO" << endl;
    return 0;
}
0