結果

問題 No.479 頂点は要らない
ユーザー tentententen
提出日時 2023-04-06 08:32:31
言語 Java21
(openjdk 21)
結果
AC  
実行時間 710 ms / 1,500 ms
コード長 2,720 bytes
コンパイル時間 2,488 ms
コンパイル使用メモリ 85,220 KB
実行使用メモリ 96,644 KB
最終ジャッジ日時 2024-04-10 07:32:10
合計ジャッジ時間 13,539 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
50,152 KB
testcase_01 AC 49 ms
50,144 KB
testcase_02 AC 52 ms
50,304 KB
testcase_03 AC 52 ms
50,140 KB
testcase_04 AC 52 ms
50,328 KB
testcase_05 AC 51 ms
49,948 KB
testcase_06 AC 51 ms
50,500 KB
testcase_07 AC 52 ms
50,456 KB
testcase_08 AC 53 ms
50,040 KB
testcase_09 AC 53 ms
50,376 KB
testcase_10 AC 52 ms
50,248 KB
testcase_11 AC 52 ms
50,256 KB
testcase_12 AC 52 ms
50,428 KB
testcase_13 AC 51 ms
50,096 KB
testcase_14 AC 50 ms
50,452 KB
testcase_15 AC 50 ms
50,492 KB
testcase_16 AC 50 ms
50,304 KB
testcase_17 AC 51 ms
50,488 KB
testcase_18 AC 52 ms
50,500 KB
testcase_19 AC 79 ms
51,540 KB
testcase_20 AC 87 ms
51,608 KB
testcase_21 AC 76 ms
51,432 KB
testcase_22 AC 81 ms
51,376 KB
testcase_23 AC 87 ms
51,376 KB
testcase_24 AC 82 ms
51,488 KB
testcase_25 AC 78 ms
51,476 KB
testcase_26 AC 663 ms
92,844 KB
testcase_27 AC 710 ms
90,696 KB
testcase_28 AC 452 ms
96,644 KB
testcase_29 AC 441 ms
77,456 KB
testcase_30 AC 429 ms
77,716 KB
testcase_31 AC 439 ms
77,656 KB
testcase_32 AC 438 ms
77,536 KB
testcase_33 AC 512 ms
78,060 KB
testcase_34 AC 542 ms
78,144 KB
testcase_35 AC 485 ms
73,328 KB
testcase_36 AC 354 ms
65,204 KB
testcase_37 AC 559 ms
78,568 KB
testcase_38 AC 469 ms
75,280 KB
testcase_39 AC 368 ms
72,144 KB
testcase_40 AC 441 ms
77,996 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[] 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();
    }
    
}
0