結果

問題 No.629 グラフの中に眠る門松列
コンテスト
ユーザー htensai
提出日時 2019-11-14 11:29:36
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 145 ms / 4,000 ms
コード長 983 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,741 ms
コンパイル使用メモリ 84,096 KB
実行使用メモリ 50,800 KB
最終ジャッジ日時 2026-04-10 03:01:41
合計ジャッジ時間 7,167 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] arr = new int[n + 1];
		TreeSet<Integer>[] graph = new TreeSet[n + 1];
		for (int i = 1; i <= n; i++) {
		    arr[i] = sc.nextInt();
		    graph[i] = new TreeSet<Integer>();
		}
		for (int i = 0; i < m; i++) {
		    int a = sc.nextInt();
		    int b = sc.nextInt();
		    graph[a].add(arr[b]);
		    graph[b].add(arr[a]);
		}
		for (int i = 1; i <= n; i++) {
		    Integer small = graph[i].lower(arr[i]);
		    if (small != null) {
		        if (graph[i].lower(small) != null) {
		            System.out.println("YES");
		            return;
		        }
		    }
		    Integer large = graph[i].higher(arr[i]);
		    if (large != null) {
		        if (graph[i].higher(large) != null) {
		            System.out.println("YES");
		            return;
		        }
		    }
		}
		System.out.println("NO");
	}
}
0