結果

問題 No.1477 Lamps on Graph
ユーザー 小野寺健小野寺健
提出日時 2021-04-26 21:43:30
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,781 bytes
コンパイル時間 7,312 ms
コンパイル使用メモリ 75,100 KB
実行使用メモリ 80,256 KB
最終ジャッジ日時 2023-09-18 17:38:10
合計ジャッジ時間 37,266 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
55,684 KB
testcase_01 AC 136 ms
55,864 KB
testcase_02 AC 130 ms
55,320 KB
testcase_03 AC 131 ms
55,508 KB
testcase_04 AC 130 ms
55,412 KB
testcase_05 AC 130 ms
55,500 KB
testcase_06 AC 131 ms
55,604 KB
testcase_07 AC 130 ms
55,824 KB
testcase_08 AC 133 ms
55,460 KB
testcase_09 AC 131 ms
55,508 KB
testcase_10 AC 134 ms
55,428 KB
testcase_11 AC 132 ms
55,884 KB
testcase_12 AC 1,314 ms
71,880 KB
testcase_13 AC 1,340 ms
71,452 KB
testcase_14 AC 1,539 ms
77,024 KB
testcase_15 AC 958 ms
69,084 KB
testcase_16 AC 786 ms
70,048 KB
testcase_17 AC 797 ms
66,896 KB
testcase_18 AC 1,703 ms
73,160 KB
testcase_19 AC 1,237 ms
72,272 KB
testcase_20 AC 767 ms
66,316 KB
testcase_21 AC 1,455 ms
70,160 KB
testcase_22 AC 638 ms
62,888 KB
testcase_23 AC 1,103 ms
69,260 KB
testcase_24 AC 1,698 ms
80,256 KB
testcase_25 AC 911 ms
67,004 KB
testcase_26 AC 1,622 ms
80,112 KB
testcase_27 AC 1,040 ms
69,348 KB
testcase_28 AC 1,146 ms
69,672 KB
testcase_29 AC 1,140 ms
68,568 KB
testcase_30 AC 1,121 ms
71,140 KB
testcase_31 AC 916 ms
67,224 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 boolean noInput;
		public Peek(int i, int A) {
			this.i = i;
			this.A = A;
			V = new ArrayList<Integer>();
			B = false;
			noInput = true;
		}
	}

	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].noInput = false;
			} else if (A[u].A < A[v].A) {
				A[u].V.add(v);
				A[v].V.add(u);
				A[v].noInput = false;				
			}
		}
		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.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;
					} 
				}
				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