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