結果
| 問題 |
No.1477 Lamps on Graph
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2024-02-08 14:53:08 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,050 ms / 2,000 ms |
| コード長 | 2,591 bytes |
| コンパイル時間 | 2,914 ms |
| コンパイル使用メモリ | 91,048 KB |
| 実行使用メモリ | 67,960 KB |
| 最終ジャッジ日時 | 2024-09-28 12:45:43 |
| 合計ジャッジ時間 | 25,755 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 38 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int m = sc.nextInt();
List<Unit> values = IntStream.range(0, n).mapToObj(i -> new Unit(i, sc.nextInt())).toList();
List<List<Integer>> graph = IntStream.range(0, n).mapToObj(i -> new ArrayList<Integer>()).collect(Collectors.toList());
IntStream.range(0, m).forEach(i -> {
int a = sc.nextInt() - 1;
int b = sc.nextInt() - 1;
if (values.get(a).value < values.get(b).value) {
graph.get(a).add(b);
} else if (values.get(b).value < values.get(a).value) {
graph.get(b).add(a);
}
});
boolean[] isOn = new boolean[n];
IntStream.range(0, sc.nextInt()).forEach(i -> {
isOn[sc.nextInt() - 1] = true;
});
List<Integer> ans = new ArrayList<>();
values.stream().sorted().forEach(x -> {
if (isOn[x.idx]) {
ans.add(x.idx + 1);
graph.get(x.idx).stream().forEach(y -> isOn[y] ^= true);
}
});
System.out.println(ans.size());
System.out.println(ans.stream().map(x -> x.toString()).collect(Collectors.joining("\n")));
}
static class Unit implements Comparable<Unit> {
int idx;
int value;
public Unit(int idx, int value) {
this.idx = idx;
this.value = value;
}
public int compareTo(Unit another) {
return value - another.value;
}
}
}
class Scanner {
BufferedReader br;
StringTokenizer st = new StringTokenizer("");
StringBuilder sb = new StringBuilder();
public Scanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
} catch (Exception e) {
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String next() {
try {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
return st.nextToken();
}
}
}
tenten