結果

問題 No.479 頂点は要らない
ユーザー tentententen
提出日時 2023-12-19 08:25:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 840 ms / 1,500 ms
コード長 2,680 bytes
コンパイル時間 2,751 ms
コンパイル使用メモリ 84,712 KB
実行使用メモリ 96,044 KB
最終ジャッジ日時 2023-12-19 08:26:12
合計ジャッジ時間 15,468 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
51,916 KB
testcase_01 AC 53 ms
53,984 KB
testcase_02 AC 54 ms
53,992 KB
testcase_03 AC 53 ms
53,992 KB
testcase_04 AC 53 ms
54,000 KB
testcase_05 AC 54 ms
54,012 KB
testcase_06 AC 53 ms
53,992 KB
testcase_07 AC 56 ms
53,988 KB
testcase_08 AC 53 ms
53,980 KB
testcase_09 AC 55 ms
53,996 KB
testcase_10 AC 54 ms
53,988 KB
testcase_11 AC 53 ms
53,988 KB
testcase_12 AC 54 ms
53,996 KB
testcase_13 AC 54 ms
53,960 KB
testcase_14 AC 55 ms
53,968 KB
testcase_15 AC 55 ms
53,996 KB
testcase_16 AC 53 ms
53,976 KB
testcase_17 AC 53 ms
53,996 KB
testcase_18 AC 54 ms
53,968 KB
testcase_19 AC 90 ms
55,152 KB
testcase_20 AC 95 ms
55,272 KB
testcase_21 AC 83 ms
55,144 KB
testcase_22 AC 91 ms
55,260 KB
testcase_23 AC 99 ms
55,148 KB
testcase_24 AC 90 ms
54,900 KB
testcase_25 AC 98 ms
54,884 KB
testcase_26 AC 840 ms
96,044 KB
testcase_27 AC 837 ms
94,148 KB
testcase_28 AC 609 ms
95,744 KB
testcase_29 AC 480 ms
80,420 KB
testcase_30 AC 455 ms
80,036 KB
testcase_31 AC 460 ms
80,404 KB
testcase_32 AC 466 ms
80,404 KB
testcase_33 AC 617 ms
81,872 KB
testcase_34 AC 670 ms
82,008 KB
testcase_35 AC 603 ms
77,360 KB
testcase_36 AC 451 ms
68,872 KB
testcase_37 AC 624 ms
82,204 KB
testcase_38 AC 596 ms
79,036 KB
testcase_39 AC 450 ms
73,804 KB
testcase_40 AC 551 ms
79,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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[] removed = new boolean[n];
        for (int i = n - 1; i >= 0; i--) {
            if (removed[i]) {
                continue;
            }
            for (int x : graph.get(i)) {
                removed[x] = true;
                for (int y : graph.get(x)) {
                    if (y == i) {
                        continue;
                    }
                    graph.get(y).remove(x);
                }
                graph.get(x).clear();
            }
        }
        boolean isFirst = true;
        StringBuilder sb = new StringBuilder();
        for (int i = n - 1; i >= 0; i--) {
            if (removed[i]) {
                sb.append("1");
                isFirst = false;
            } else {
                if (!isFirst) {
                    sb.append("0");
                }
            }
        }
        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();
    }
    
}
0