結果

問題 No.629 グラフの中に眠る門松列
ユーザー cidercider
提出日時 2018-01-10 18:37:51
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,306 bytes
コンパイル時間 945 ms
コンパイル使用メモリ 73,964 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-23 15:43:14
合計ジャッジ時間 2,243 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 5
other AC * 12 WA * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<functional>
#define For(i, N) for (i = 0; i < N; i++)
#define rep(N) for (int i = 0; i < N; i++)
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vb = vector<bool>;
using vs = vector<string>;
using pib = pair<int, bool>;
using pii = pair<int, int>;

template<typename T>
void say(T s) {
	cout << s << endl;
}

int main() {
	int N, M;
	cin >> N >> M;
	int A;
	int U, V;
	int i, j;
	vector<int> a;
	vector<pii> u;
	rep(N) {
		cin >> A;
		a.push_back(A);
	}
	rep(M) {
		cin >> U >> V;
		u.push_back({ U - 1,V - 1 });
	}
	for (i = 0; i < M; i++)
		for (j = i + 1; j < M; j++) {
			int x, y, z;
			bool flag = false;
			if (u[i].first == u[j].first) {
				x = u[i].first;
				y = u[i].second;
				z = u[j].second;
			}
			else if (u[i].first == u[j].second) {
				x = u[i].first;
				y = u[i].first;
				z = u[i].first;
			}
			else if (u[i].second == u[j].first) {
				x = u[i].second;
				y = u[i].first;
				z = u[j].second;
			}
			else {
				x = u[i].second;
				y = u[i].first;
				z = u[j].first;
			}
			if (flag) {
				if (((a[x] < y&&a[x] < a[z]) || (a[x] > a[y] && a[x] > a[z])) && a[y] != a[z]) {
					say("YES");
					re;
				}
			}
		}
	say("NO");

}
0