結果
| 問題 | No.479 頂点は要らない |
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2020-05-08 19:59:42 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,351 ms / 1,500 ms |
| コード長 | 1,300 bytes |
| コンパイル時間 | 2,879 ms |
| コンパイル使用メモリ | 79,272 KB |
| 実行使用メモリ | 101,696 KB |
| 最終ジャッジ日時 | 2024-12-16 18:24:29 |
| 合計ジャッジ時間 | 25,724 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
ソースコード
import java.util.*;
public class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
ArrayList<HashSet<Integer>> graph = new ArrayList<>();
for (int i = 0; i < n; i++) {
graph.add(new HashSet<>());
}
for (int i = 0; i < m; i++) {
int a = sc.nextInt();
int b = sc.nextInt();
graph.get(a).add(b);
graph.get(b).add(a);
}
boolean[] needs = new boolean[n];
for (int i = n - 1; i >= 0; i--) {
if (needs[i]) {
continue;
} else {
if (graph.get(i).size() == 0) {
continue;
}
for (int x : graph.get(i)) {
needs[x] = true;
for (int y : graph.get(x)) {
if(i == y) {
continue;
}
graph.get(y).remove(x);
}
graph.get(x).clear();
}
graph.get(i).clear();
}
}
StringBuilder sb = new StringBuilder();
boolean isFirst = true;
for (int i = n - 1; i >= 0; i--) {
if (needs[i]) {
sb.append("1");
isFirst = false;
} else if (!isFirst) {
sb.append("0");
}
}
System.out.println(sb);
}
}
htensai