結果
問題 | No.479 頂点は要らない |
ユーザー | tenten |
提出日時 | 2023-04-06 08:32:31 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 674 ms / 1,500 ms |
コード長 | 2,720 bytes |
コンパイル時間 | 2,638 ms |
コンパイル使用メモリ | 85,660 KB |
実行使用メモリ | 92,436 KB |
最終ジャッジ日時 | 2024-10-02 09:15:55 |
合計ジャッジ時間 | 12,841 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
50,328 KB |
testcase_01 | AC | 48 ms
50,460 KB |
testcase_02 | AC | 49 ms
50,160 KB |
testcase_03 | AC | 48 ms
50,240 KB |
testcase_04 | AC | 48 ms
50,236 KB |
testcase_05 | AC | 49 ms
50,392 KB |
testcase_06 | AC | 47 ms
50,136 KB |
testcase_07 | AC | 50 ms
50,248 KB |
testcase_08 | AC | 51 ms
50,396 KB |
testcase_09 | AC | 47 ms
50,460 KB |
testcase_10 | AC | 50 ms
50,352 KB |
testcase_11 | AC | 49 ms
50,204 KB |
testcase_12 | AC | 49 ms
50,332 KB |
testcase_13 | AC | 48 ms
50,388 KB |
testcase_14 | AC | 51 ms
50,024 KB |
testcase_15 | AC | 52 ms
50,312 KB |
testcase_16 | AC | 52 ms
50,140 KB |
testcase_17 | AC | 49 ms
49,948 KB |
testcase_18 | AC | 51 ms
50,316 KB |
testcase_19 | AC | 94 ms
51,132 KB |
testcase_20 | AC | 82 ms
51,352 KB |
testcase_21 | AC | 84 ms
50,904 KB |
testcase_22 | AC | 89 ms
51,408 KB |
testcase_23 | AC | 90 ms
51,352 KB |
testcase_24 | AC | 89 ms
51,392 KB |
testcase_25 | AC | 85 ms
51,180 KB |
testcase_26 | AC | 608 ms
92,328 KB |
testcase_27 | AC | 674 ms
92,436 KB |
testcase_28 | AC | 501 ms
92,012 KB |
testcase_29 | AC | 402 ms
77,452 KB |
testcase_30 | AC | 392 ms
77,520 KB |
testcase_31 | AC | 422 ms
77,620 KB |
testcase_32 | AC | 405 ms
77,560 KB |
testcase_33 | AC | 485 ms
77,712 KB |
testcase_34 | AC | 499 ms
77,928 KB |
testcase_35 | AC | 448 ms
73,408 KB |
testcase_36 | AC | 319 ms
65,220 KB |
testcase_37 | AC | 502 ms
78,744 KB |
testcase_38 | AC | 438 ms
75,092 KB |
testcase_39 | AC | 342 ms
71,912 KB |
testcase_40 | AC | 418 ms
77,904 KB |
ソースコード
import java.io.*; import java.util.*; 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(); 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[] visited = new boolean[n]; char[] ans = new char[n]; for (int i = n - 1; i >= 0; i--) { if (visited[i]) { continue; } visited[i] = true; ans[n - i - 1] = '0'; for (int x : graph.get(i)) { visited[x] = true; ans[n - x - 1] = '1'; for (int y : graph.get(x)) { if (y != i) { graph.get(y).remove(x); } } } } StringBuilder sb = new StringBuilder(); boolean isStart = true; for (char c : ans) { if (c == '0') { if (isStart) { continue; } } else { isStart = false; } sb.append(c); } System.out.println(sb); } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }