結果

問題 No.1477 Lamps on Graph
ユーザー 小野寺健小野寺健
提出日時 2021-04-26 21:49:55
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,733 bytes
コンパイル時間 5,426 ms
コンパイル使用メモリ 74,984 KB
実行使用メモリ 88,564 KB
最終ジャッジ日時 2023-09-18 17:49:44
合計ジャッジ時間 34,451 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,596 KB
testcase_01 AC 123 ms
55,688 KB
testcase_02 AC 123 ms
56,072 KB
testcase_03 AC 124 ms
55,832 KB
testcase_04 AC 123 ms
56,016 KB
testcase_05 AC 125 ms
56,160 KB
testcase_06 AC 126 ms
55,840 KB
testcase_07 AC 124 ms
55,780 KB
testcase_08 AC 123 ms
55,560 KB
testcase_09 AC 126 ms
56,052 KB
testcase_10 AC 123 ms
55,608 KB
testcase_11 AC 122 ms
55,772 KB
testcase_12 AC 1,283 ms
81,020 KB
testcase_13 AC 1,340 ms
79,144 KB
testcase_14 AC 1,473 ms
82,384 KB
testcase_15 AC 879 ms
71,400 KB
testcase_16 AC 746 ms
69,320 KB
testcase_17 AC 778 ms
69,552 KB
testcase_18 AC 1,661 ms
79,528 KB
testcase_19 AC 1,288 ms
80,272 KB
testcase_20 AC 731 ms
66,740 KB
testcase_21 AC 1,445 ms
77,572 KB
testcase_22 AC 594 ms
63,116 KB
testcase_23 AC 1,051 ms
70,676 KB
testcase_24 AC 1,705 ms
88,564 KB
testcase_25 AC 835 ms
69,316 KB
testcase_26 AC 1,564 ms
83,100 KB
testcase_27 AC 995 ms
71,304 KB
testcase_28 AC 1,126 ms
79,672 KB
testcase_29 AC 1,096 ms
71,932 KB
testcase_30 AC 1,118 ms
70,684 KB
testcase_31 AC 881 ms
69,096 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 List<Integer> input;
		public Peek(int i, int A) {
			this.i = i;
			this.A = A;
			V = new ArrayList<Integer>();
			B = false;
			input = new ArrayList<Integer>();
		}
	}

	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;
			if (A[u].A > A[v].A) {
				A[u].V.add(v);
				A[v].V.add(u);
				A[u].input.add(v);
			} else if (A[u].A < A[v].A) {
				A[u].V.add(v);
				A[v].V.add(u);
				A[v].input.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) {
			if (p.input.isEmpty()) {
				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);
				m.input.remove((Object)n.i);
				if (b) {
					m.B = !m.B;
				}
				if (m.input.isEmpty()) {
					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