結果
問題 |
No.629 グラフの中に眠る門松列
|
ユーザー |
|
提出日時 | 2020-04-16 09:23:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 4,000 ms |
コード長 | 1,289 bytes |
コンパイル時間 | 1,272 ms |
コンパイル使用メモリ | 85,040 KB |
最終ジャッジ日時 | 2025-01-09 19:24:30 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 36 |
ソースコード
#include <iostream> #include <vector> #include <set> template <class Cost = int> struct Edge { int src, dst; Cost cost; Edge(int src = -1, int dst = -1, Cost cost = 1) : src(src), dst(dst), cost(cost){}; bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; } bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; } }; template <class Cost = int> using Graph = std::vector<std::vector<Edge<Cost>>>; void solve() { int n, m; std::cin >> n >> m; std::vector<int> xs(n); for (auto& x : xs) std::cin >> x; Graph<> graph(n); while (m--) { int u, v; std::cin >> u >> v; --u, --v; graph[u].emplace_back(u, v); graph[v].emplace_back(v, u); } for (int v = 0; v < n; ++v) { auto x = xs[v]; std::set<int> ls, rs; for (auto e : graph[v]) { auto y = xs[e.dst]; if (y < x) ls.insert(y); if (y > x) rs.insert(y); } if (ls.size() > 1 || rs.size() > 1) { std::cout << "YES" << std::endl; return; } } std::cout << "NO" << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }