結果

問題 No.479 頂点は要らない
ユーザー tenten
提出日時 2020-09-11 09:47:12
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,235 ms / 1,500 ms
コード長 915 bytes
コンパイル時間 2,540 ms
コンパイル使用メモリ 80,000 KB
実行使用メモリ 96,592 KB
最終ジャッジ日時 2024-12-25 08:38:18
合計ジャッジ時間 22,669 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

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<TreeSet<Integer>> graph = new ArrayList<>();
    	for (int i = 0; i < n; i++) {
    	    graph.add(new TreeSet<>());
    	}
    	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);
    	}
    	StringBuilder sb = new StringBuilder();
    	for (int i = n - 1; i >= 0; i--) {
    	    if (graph.get(i).size() > 0 && graph.get(i).last() > i) {
    	        sb.append("1");
    	        for (int x : graph.get(i)) {
    	            graph.get(x).remove(i);
    	        }
    	    } else {
    	        if (sb.length() > 0) {
    	            sb.append("0");
    	        }
    	    }
    	}
    	System.out.println(sb);
	}
}
0