結果

問題 No.479 頂点は要らない
ユーザー htensaihtensai
提出日時 2020-05-08 19:59:42
言語 Java19
(openjdk 21)
結果
AC  
実行時間 1,208 ms / 1,500 ms
コード長 1,300 bytes
コンパイル時間 2,340 ms
コンパイル使用メモリ 75,828 KB
実行使用メモリ 99,040 KB
最終ジャッジ日時 2023-09-16 08:35:21
合計ジャッジ時間 23,654 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,644 KB
testcase_01 AC 122 ms
55,824 KB
testcase_02 AC 123 ms
55,680 KB
testcase_03 AC 121 ms
56,004 KB
testcase_04 AC 126 ms
55,424 KB
testcase_05 AC 125 ms
55,644 KB
testcase_06 AC 122 ms
55,640 KB
testcase_07 AC 123 ms
56,004 KB
testcase_08 AC 123 ms
55,576 KB
testcase_09 AC 123 ms
55,636 KB
testcase_10 AC 125 ms
56,040 KB
testcase_11 AC 125 ms
55,928 KB
testcase_12 AC 126 ms
55,488 KB
testcase_13 AC 125 ms
55,404 KB
testcase_14 AC 130 ms
55,752 KB
testcase_15 AC 131 ms
55,624 KB
testcase_16 AC 125 ms
55,528 KB
testcase_17 AC 125 ms
55,408 KB
testcase_18 AC 126 ms
55,736 KB
testcase_19 AC 207 ms
58,616 KB
testcase_20 AC 201 ms
58,736 KB
testcase_21 AC 204 ms
58,680 KB
testcase_22 AC 207 ms
58,236 KB
testcase_23 AC 193 ms
58,296 KB
testcase_24 AC 202 ms
58,444 KB
testcase_25 AC 201 ms
58,020 KB
testcase_26 AC 1,199 ms
97,244 KB
testcase_27 AC 1,196 ms
95,472 KB
testcase_28 AC 926 ms
99,040 KB
testcase_29 AC 948 ms
88,084 KB
testcase_30 AC 934 ms
88,176 KB
testcase_31 AC 900 ms
88,280 KB
testcase_32 AC 899 ms
88,096 KB
testcase_33 AC 1,101 ms
83,312 KB
testcase_34 AC 1,208 ms
85,000 KB
testcase_35 AC 1,133 ms
81,400 KB
testcase_36 AC 849 ms
70,724 KB
testcase_37 AC 1,170 ms
88,544 KB
testcase_38 AC 1,010 ms
81,372 KB
testcase_39 AC 819 ms
79,140 KB
testcase_40 AC 895 ms
81,636 KB
権限があれば一括ダウンロードができます

ソースコード

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