結果

問題 No.629 グラフの中に眠る門松列
ユーザー YamaKasaYamaKasa
提出日時 2018-09-30 14:50:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 238 ms / 4,000 ms
コード長 1,552 bytes
コンパイル時間 1,883 ms
コンパイル使用メモリ 79,008 KB
実行使用メモリ 47,716 KB
最終ジャッジ日時 2024-04-20 13:36:16
合計ジャッジ時間 10,164 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
41,264 KB
testcase_01 AC 101 ms
40,036 KB
testcase_02 AC 132 ms
41,684 KB
testcase_03 AC 122 ms
41,620 KB
testcase_04 AC 110 ms
40,520 KB
testcase_05 AC 116 ms
41,516 KB
testcase_06 AC 109 ms
40,980 KB
testcase_07 AC 108 ms
40,856 KB
testcase_08 AC 114 ms
41,200 KB
testcase_09 AC 105 ms
40,440 KB
testcase_10 AC 113 ms
41,440 KB
testcase_11 AC 115 ms
41,644 KB
testcase_12 AC 117 ms
41,672 KB
testcase_13 AC 114 ms
41,620 KB
testcase_14 AC 110 ms
41,292 KB
testcase_15 AC 108 ms
40,396 KB
testcase_16 AC 105 ms
40,704 KB
testcase_17 AC 112 ms
41,388 KB
testcase_18 AC 115 ms
41,592 KB
testcase_19 AC 115 ms
41,452 KB
testcase_20 AC 111 ms
41,112 KB
testcase_21 AC 181 ms
44,948 KB
testcase_22 AC 193 ms
44,844 KB
testcase_23 AC 185 ms
44,660 KB
testcase_24 AC 232 ms
46,944 KB
testcase_25 AC 213 ms
45,940 KB
testcase_26 AC 219 ms
46,820 KB
testcase_27 AC 237 ms
47,320 KB
testcase_28 AC 175 ms
43,160 KB
testcase_29 AC 213 ms
46,140 KB
testcase_30 AC 233 ms
47,256 KB
testcase_31 AC 238 ms
47,716 KB
testcase_32 AC 227 ms
47,376 KB
testcase_33 AC 237 ms
47,128 KB
testcase_34 AC 218 ms
46,976 KB
testcase_35 AC 218 ms
46,060 KB
testcase_36 AC 230 ms
47,140 KB
testcase_37 AC 209 ms
46,000 KB
testcase_38 AC 238 ms
47,444 KB
testcase_39 AC 224 ms
45,968 KB
testcase_40 AC 206 ms
45,492 KB
testcase_41 AC 202 ms
46,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int M = scan.nextInt();
		int[]a = new int[N];
		for(int i = 0; i < N; i++) {
			a[i] = scan.nextInt();
		}
		int[]u = new int[M];
		int[]v = new int[M];
		for(int i = 0; i < M; i++) {
			u[i] = scan.nextInt();
			v[i] = scan.nextInt();
		}
		scan.close();
		Map<Integer, ArrayList<Integer>> G
		= new HashMap<Integer, ArrayList<Integer>>();
		for(int i = 0; i < M; i++) {
			if(G.containsKey(u[i])) {
				G.get(u[i]).add(v[i]);
			}else {
				ArrayList<Integer> list = new ArrayList<Integer>();
				list.add(v[i]);
				G.put(u[i], list);
			}
			if(G.containsKey(v[i])) {
				G.get(v[i]).add(u[i]);
			}else {
				ArrayList<Integer> list = new ArrayList<Integer>();
				list.add(u[i]);
				G.put(v[i], list);
			}
		}
		for(int k : G.keySet()) {
			ArrayList<Integer> list = G.get(k);
			if(list.size() >= 2) {
				int t1 = a[k - 1];
				Set<Integer> up = new HashSet<Integer>();
				Set<Integer> dw = new HashSet<Integer>();
				for(int i = 0; i < list.size(); i++) {
					if(t1 > a[list.get(i) - 1]) {
						up.add(a[list.get(i) - 1]);
					}else if(t1 < a[list.get(i) - 1]) {
						dw.add(a[list.get(i) - 1]);
					}
				}
				if(up.size() >= 2 || dw.size() >= 2) {
					System.out.println("YES");
					System.exit(0);
				}
			}
		}
		System.out.println("NO");
	}
}
0