結果
| 問題 |
No.629 グラフの中に眠る門松列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-09 22:38:19 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 47 ms / 4,000 ms |
| コード長 | 1,304 bytes |
| コンパイル時間 | 1,853 ms |
| コンパイル使用メモリ | 172,748 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-06 05:12:43 |
| 合計ジャッジ時間 | 3,286 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 36 |
ソースコード
#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;
}