結果

問題 No.1477 Lamps on Graph
ユーザー 小野寺健小野寺健
提出日時 2021-04-26 20:43:39
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,802 bytes
コンパイル時間 6,091 ms
コンパイル使用メモリ 74,920 KB
実行使用メモリ 80,200 KB
最終ジャッジ日時 2023-09-18 16:21:20
合計ジャッジ時間 36,389 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
57,760 KB
testcase_01 AC 127 ms
55,880 KB
testcase_02 AC 126 ms
55,616 KB
testcase_03 AC 127 ms
55,600 KB
testcase_04 AC 129 ms
55,680 KB
testcase_05 RE -
testcase_06 AC 129 ms
55,788 KB
testcase_07 AC 129 ms
55,844 KB
testcase_08 AC 128 ms
55,680 KB
testcase_09 AC 127 ms
55,956 KB
testcase_10 RE -
testcase_11 AC 130 ms
55,856 KB
testcase_12 AC 1,364 ms
71,852 KB
testcase_13 AC 1,357 ms
71,672 KB
testcase_14 AC 1,555 ms
77,484 KB
testcase_15 AC 1,042 ms
71,220 KB
testcase_16 AC 793 ms
69,424 KB
testcase_17 AC 788 ms
67,508 KB
testcase_18 AC 1,723 ms
75,436 KB
testcase_19 AC 1,311 ms
71,840 KB
testcase_20 AC 766 ms
66,228 KB
testcase_21 AC 1,510 ms
72,000 KB
testcase_22 AC 627 ms
64,260 KB
testcase_23 AC 1,144 ms
69,176 KB
testcase_24 AC 1,733 ms
80,200 KB
testcase_25 AC 898 ms
66,944 KB
testcase_26 AC 1,581 ms
80,044 KB
testcase_27 AC 1,093 ms
69,612 KB
testcase_28 AC 1,209 ms
71,364 KB
testcase_29 AC 1,124 ms
69,200 KB
testcase_30 AC 1,143 ms
71,952 KB
testcase_31 AC 904 ms
67,336 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class No1477 {
	
	private static class Peek {
		public int i, A;
		public List<Integer> V;
		public boolean B;
		public Peek(int i, int A) {
			this.i = i;
			this.A = A;
			V = new ArrayList<Integer>();
			B = false;
		}
	}

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int M = scan.nextInt();
		Peek[] A = new Peek[N];
		for (int i=0; i < N; i++) {
			A[i] = new Peek(i, scan.nextInt());
		}
		for (int i = 0; i < M; i++) {
			int u = scan.nextInt() - 1;
			int v = scan.nextInt() - 1;
			A[u].V.add(v);
			A[v].V.add(u);
		}
		int K = scan.nextInt();
		for (int i = 0; i < K; i++) {
			int b = scan.nextInt() - 1;
			A[b].B = true;
		}
		scan.close();
		List<Peek> S = new ArrayList<Peek>();
		for (Peek p : A) {
			boolean noInput = true;
			for (int i : p.V) {
				if (p.A > A[i].A) {
					noInput = false;
				} else if (p.A == A[i].A) {
					p.V.remove((Object)i);
				}
			}
			if (noInput) {
				S.add(p);
			}
		}
		List<Integer> op = new ArrayList<Integer>();
		while(!S.isEmpty()) {
			Peek n = S.remove(0);
			boolean b = n.B;
			if (b) {
				n.B = false;
				op.add(n.i + 1);
			}
			for (int i : n.V) {
				Peek m = A[i];
				m.V.remove((Object)n.i);
				if (b) {
					m.B = !m.B;
				}
				boolean noInput = true;
				for (int j : m.V) {
					if (m.A > A[j].A) {
						noInput = false;
					} else if (m.A == A[j].A) {
						m.V.remove((Object)j);
					}
				}
				if (noInput) {
					S.add(m);
				}
			}
		}
		boolean b = false;
		for (Peek p : A) {
			b |= p.B;
		}
		if (b) {
			System.out.println(-1);
		} else {
			System.out.println(op.size());
			for (int p : op) {
				System.out.println(p);
			}
		}
	}

}
0