結果
問題 | No.629 グラフの中に眠る門松列 |
ユーザー |
|
提出日時 | 2018-01-05 22:08:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 21 ms / 4,000 ms |
コード長 | 1,379 bytes |
コンパイル時間 | 579 ms |
コンパイル使用メモリ | 67,876 KB |
最終ジャッジ日時 | 2025-01-05 07:04:18 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 36 |
ソースコード
#include <iostream> using namespace std; struct Edge { int u, v; }; int n,m; int a[1010]; Edge es[4010]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (int i = 1; i < n + 1; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; es[i] = Edge({u, v}); } for (int i = 0; i < m; i++) { for (int j = i + 1; j < m; j++) { int x, y, z; x = y = z = 0; if (es[i].u == es[j].u) { x = es[i].v, y = es[i].u, z = es[j].v; } else if (es[i].u == es[j].v) { x = es[i].v, y = es[i].u, z = es[j].u; } else if (es[i].v == es[j].u) { x = es[i].u, y = es[i].v, z = es[j].v; } else if (es[i].v == es[j].v) { x = es[i].u, y = es[i].v, z = es[j].u; } if (x) { // cout << x << ' ' << y << ' ' << z << endl; x = a[x], y = a[y], z = a[z]; if ((x < y && y > z && x != z) || (x > y && y < z && x != z)) { cout << "YES" << endl; return 0; } } } } cout << "NO" << endl; return 0; }