結果

問題 No.629 グラフの中に眠る門松列
ユーザー htensai
提出日時 2019-11-14 11:29:36
言語 Java
(openjdk 23)
結果
AC  
実行時間 264 ms / 4,000 ms
コード長 983 bytes
コンパイル時間 2,346 ms
コンパイル使用メモリ 78,108 KB
実行使用メモリ 46,972 KB
最終ジャッジ日時 2024-09-21 21:22:21
合計ジャッジ時間 11,855 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

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