結果

問題 No.479 頂点は要らない
ユーザー tenten
提出日時 2021-11-11 18:50:28
言語 Java
(openjdk 23)
結果
AC  
実行時間 881 ms / 1,500 ms
コード長 2,080 bytes
コンパイル時間 2,655 ms
コンパイル使用メモリ 78,604 KB
実行使用メモリ 93,080 KB
最終ジャッジ日時 2024-11-23 05:36:04
合計ジャッジ時間 15,768 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

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[] delete = new boolean[n];
        for (int i = n - 1; i >= 0; i--) {
            if (delete[i]) {
                for (int x : graph.get(i)) {
                    graph.get(x).remove(i);
                }
            } else {
                for (int x : graph.get(i)) {
                    delete[x] = true;
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        boolean isFirst = true;
        for (int i = n - 1; i >= 0; i--) {
            if (delete[i]) {
                sb.append("1");
                isFirst = false;
            } else {
                if (!isFirst) {
                    sb.append("0");
                }
            }
        }
        System.out.println(sb);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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 String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0