結果
問題 |
No.629 グラフの中に眠る門松列
|
ユーザー |
![]() |
提出日時 | 2018-01-18 13:54:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 797 bytes |
コンパイル時間 | 2,206 ms |
コンパイル使用メモリ | 199,556 KB |
最終ジャッジ日時 | 2025-01-05 07:39:41 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 16 MLE * 20 |
ソースコード
#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<vector<int>> g(n); while (m--) { int u, v; cin>>u>>v; --u, --v; g[u].push_back(v); g[v].push_back(u); } 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]; }; function<bool(int, int, int)> dfs=[&](int i, int j, int k) { if (k>=0 && is_kadomatsu(i, j, k)) return true; for(int v: g[i]) if (v!=j and dfs(v, i, j)) return true; return false; }; for(int i=0; i<n; ++i) { if (dfs(i, -1, -1)) return cout<<"YES"<<endl, 0; } cout<<"NO"<<endl; }