結果

問題 No.629 グラフの中に眠る門松列
ユーザー ldsyb
提出日時 2018-01-07 00:44:54
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 59 ms / 4,000 ms
コード長 824 bytes
コンパイル時間 1,715 ms
コンパイル使用メモリ 170,896 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-23 09:20:54
合計ジャッジ時間 3,398 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	int a[n];
	for (auto &i : a) {
		cin >> i;
	}
	vector<int> from, to;
	for (int i = 0; i < m; i++) {
		int puni, muni;
		cin >> puni >> muni;
		puni--;
		muni--;
		from.emplace_back(puni);
		to.emplace_back(muni);
		from.emplace_back(muni);
		to.emplace_back(puni);
	}
	for (int i = 0; i < 2 * m; i++) {
		for (int j = 0; j < 2 * m; j++) {
			if (i == j || to[i] != from[j] || from[i] == to[j] || a[from[i]] == a[to[i]] || a[from[i]] == a[to[j]] || a[to[i]] == a[to[j]]) {
				continue;
			}
			int min_v = min({a[from[i]], a[to[i]], a[to[j]]});
			int max_v = max({a[from[i]], a[to[i]], a[to[j]]});
			if (min_v == a[to[i]] || max_v == a[to[i]]) {
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}
0