結果

問題 No.629 グラフの中に眠る門松列
ユーザー htensaihtensai
提出日時 2019-11-14 11:29:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 269 ms / 4,000 ms
コード長 983 bytes
コンパイル時間 2,175 ms
コンパイル使用メモリ 78,560 KB
実行使用メモリ 61,304 KB
最終ジャッジ日時 2023-10-21 19:57:05
合計ジャッジ時間 12,131 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
57,440 KB
testcase_01 AC 136 ms
57,416 KB
testcase_02 AC 136 ms
57,440 KB
testcase_03 AC 136 ms
57,504 KB
testcase_04 AC 135 ms
57,416 KB
testcase_05 AC 136 ms
57,464 KB
testcase_06 AC 134 ms
57,436 KB
testcase_07 AC 135 ms
57,416 KB
testcase_08 AC 135 ms
57,440 KB
testcase_09 AC 135 ms
57,352 KB
testcase_10 AC 134 ms
57,400 KB
testcase_11 AC 133 ms
57,412 KB
testcase_12 AC 136 ms
57,464 KB
testcase_13 AC 136 ms
57,408 KB
testcase_14 AC 136 ms
57,404 KB
testcase_15 AC 136 ms
57,380 KB
testcase_16 AC 134 ms
57,436 KB
testcase_17 AC 135 ms
57,384 KB
testcase_18 AC 136 ms
57,412 KB
testcase_19 AC 141 ms
57,516 KB
testcase_20 AC 135 ms
57,348 KB
testcase_21 AC 220 ms
60,448 KB
testcase_22 AC 210 ms
60,552 KB
testcase_23 AC 216 ms
60,080 KB
testcase_24 AC 244 ms
60,548 KB
testcase_25 AC 249 ms
60,792 KB
testcase_26 AC 249 ms
60,624 KB
testcase_27 AC 260 ms
61,088 KB
testcase_28 AC 209 ms
59,940 KB
testcase_29 AC 246 ms
60,532 KB
testcase_30 AC 262 ms
60,968 KB
testcase_31 AC 256 ms
61,208 KB
testcase_32 AC 261 ms
61,076 KB
testcase_33 AC 263 ms
61,192 KB
testcase_34 AC 245 ms
60,460 KB
testcase_35 AC 247 ms
60,824 KB
testcase_36 AC 269 ms
61,304 KB
testcase_37 AC 247 ms
60,904 KB
testcase_38 AC 259 ms
61,104 KB
testcase_39 AC 242 ms
59,092 KB
testcase_40 AC 220 ms
60,564 KB
testcase_41 AC 229 ms
60,624 KB
権限があれば一括ダウンロードができます

ソースコード

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