結果

問題 No.1477 Lamps on Graph
ユーザー 小野寺健小野寺健
提出日時 2021-04-26 20:54:10
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,004 bytes
コンパイル時間 3,644 ms
コンパイル使用メモリ 74,616 KB
実行使用メモリ 82,604 KB
最終ジャッジ日時 2023-09-18 16:35:17
合計ジャッジ時間 13,260 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
56,348 KB
testcase_01 AC 129 ms
55,388 KB
testcase_02 AC 128 ms
56,064 KB
testcase_03 AC 128 ms
56,284 KB
testcase_04 AC 124 ms
53,740 KB
testcase_05 AC 128 ms
55,948 KB
testcase_06 AC 129 ms
55,780 KB
testcase_07 AC 128 ms
55,780 KB
testcase_08 AC 127 ms
56,000 KB
testcase_09 AC 127 ms
55,616 KB
testcase_10 AC 129 ms
56,416 KB
testcase_11 AC 125 ms
56,052 KB
testcase_12 AC 1,371 ms
72,048 KB
testcase_13 AC 1,361 ms
72,236 KB
testcase_14 AC 1,604 ms
77,548 KB
testcase_15 AC 1,149 ms
69,844 KB
testcase_16 AC 803 ms
69,316 KB
testcase_17 AC 821 ms
66,924 KB
testcase_18 AC 1,656 ms
73,684 KB
testcase_19 AC 1,353 ms
71,988 KB
testcase_20 AC 768 ms
67,760 KB
testcase_21 AC 1,551 ms
72,520 KB
testcase_22 AC 625 ms
65,500 KB
testcase_23 AC 1,139 ms
68,784 KB
testcase_24 AC 1,748 ms
82,604 KB
testcase_25 AC 928 ms
67,388 KB
testcase_26 AC 1,612 ms
80,508 KB
testcase_27 AC 1,062 ms
69,732 KB
testcase_28 AC 1,201 ms
73,900 KB
testcase_29 AC 1,192 ms
69,492 KB
testcase_30 AC 1,158 ms
70,288 KB
testcase_31 AC 909 ms
67,204 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;
			List<Integer> rlist = new ArrayList<Integer>();
			for (int i : p.V) {
				if (p.A > A[i].A) {
					noInput = false;
				} else if (p.A == A[i].A) {
					rlist.add(i);
				}
			}
			for (int i : rlist) {
				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;
				List<Integer> rlist = new ArrayList<Integer>();
				for (int j : m.V) {
					if (m.A > A[j].A) {
						noInput = false;
					} else if (m.A == A[j].A) {
						rlist.add(j);
					}
				}
				for (int j : rlist) {
					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