結果

問題 No.629 グラフの中に眠る門松列
ユーザー Ryu
提出日時 2018-01-16 20:47:48
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 4,000 ms
コード長 1,034 bytes
コンパイル時間 885 ms
コンパイル使用メモリ 91,944 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-24 05:53:30
合計ジャッジ時間 2,021 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <numeric>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <stack>

const int MOD = 1e9 + 7;
const int iINF = 100000000;
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct{int to; int cost;};


int N, M, a[1000];
vector<int> graph[1000];


int main()
{
    cin >> N >> M;
    rep(i, N) cin >> a[i];
    rep(i, M)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    string ans = "NO";

    rep(i, N)
    {
        set<int> up, dn;
        for(auto to : graph[i])
        {
            if(a[i] < a[to]) up.insert(a[to]);
            if(a[i] > a[to]) dn.insert(a[to]);
        }

        if(2 <= up.size() || 2 <= dn.size()) 
        {
            ans = "YES";
            break;
        }
    }

    cout << ans << endl;


    return 0;
}
0