結果
| 問題 | No.629 グラフの中に眠る門松列 | 
| コンテスト | |
| ユーザー |  dnish | 
| 提出日時 | 2018-06-16 10:17:21 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 4 ms / 4,000 ms | 
| コード長 | 1,014 bytes | 
| コンパイル時間 | 1,636 ms | 
| コンパイル使用メモリ | 169,612 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-30 16:10:03 | 
| 合計ジャッジ時間 | 2,840 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 6 | 
| other | AC * 36 | 
ソースコード
#include "bits/stdc++.h"
#define REP(i,n,N) for(int i=(n); i<(N); i++)
#define RREP(i,n,N) for(int i=(N-1); i>=n; i--)
#define CK(n,a,b) (a)<=(n)&&(n)<(b)
#define ALL(v) (v).begin(),(v).end()
#define p(s) cout<<(s)<<endl
typedef long long ll;
using namespace std;
const int inf =1e9+7;
int main(){
    int N,M;
    while(cin>>N>>M){
        int a[1010];
        vector<int> edge[1010];
        REP(i,0,N){
            cin>>a[i];
        }
        REP(i,0,M){
            int u,v;
            cin>>u>>v;
            u--;v--;
            edge[u].push_back(v);
            edge[v].push_back(u);
        }
        bool ok=false;
        REP(i,0,N){
            for(auto e:edge[i]){
                if(a[i]==a[e]) continue;
                for(auto v:edge[e]){
                    if(a[e]==a[v]||a[v]==a[i]) continue;
                    if((a[i]<a[e]&&a[e]<a[v])||(a[i]>a[e]&&a[e]>a[v])) continue;
                    ok=true;
                }
            }
        }
        p(ok?"YES":"NO");
    }
    return 0;
}
            
            
            
        