結果
問題 |
No.1477 Lamps on Graph
|
ユーザー |
|
提出日時 | 2021-04-26 21:20:33 |
言語 | Java (openjdk 23) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,073 bytes |
コンパイル時間 | 3,404 ms |
コンパイル使用メモリ | 77,844 KB |
実行使用メモリ | 81,852 KB |
最終ジャッジ日時 | 2024-07-05 07:17:47 |
合計ジャッジ時間 | 31,487 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 7 WA * 2 RE * 21 TLE * 1 -- * 7 |
ソースコード
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=0; i < p.V.size(); i++) { int j = p.V.get(i); if (p.A > A[j].A) { noInput = false; } else if (p.A == A[i].A) { rlist.add(j); } } for (int i : rlist) { p.V.remove(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 = 0; j < m.V.size(); j++) { int k = m.V.get(j); if (m.A > A[k].A) { noInput = false; } else if (m.A == A[k].A) { rlist.add(k); } } for (int j : rlist) { m.V.remove(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); } } } }