結果

問題 No.679 不思議マーケット
ユーザー 37zigen37zigen
提出日時 2018-05-04 03:26:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 277 ms / 2,000 ms
コード長 1,053 bytes
コンパイル時間 2,715 ms
コンパイル使用メモリ 76,928 KB
実行使用メモリ 60,520 KB
最終ジャッジ日時 2023-09-10 09:28:59
合計ジャッジ時間 6,479 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,744 KB
testcase_01 AC 123 ms
56,060 KB
testcase_02 AC 124 ms
56,116 KB
testcase_03 AC 277 ms
60,520 KB
testcase_04 AC 216 ms
59,296 KB
testcase_05 AC 225 ms
57,428 KB
testcase_06 AC 198 ms
58,556 KB
testcase_07 AC 192 ms
58,336 KB
testcase_08 AC 209 ms
59,172 KB
testcase_09 AC 124 ms
56,060 KB
testcase_10 AC 195 ms
58,316 KB
testcase_11 AC 194 ms
58,440 KB
testcase_12 AC 199 ms
58,352 KB
testcase_13 AC 199 ms
58,608 KB
testcase_14 AC 196 ms
58,428 KB
testcase_15 AC 186 ms
58,116 KB
testcase_16 AC 123 ms
55,712 KB
testcase_17 AC 125 ms
55,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] deg = new int[n];
		ArrayList<Integer>[] g = new ArrayList[n];
		for (int i = 0; i < g.length; ++i)
			g[i] = new ArrayList<>();
		for (int i = 0; i < m; ++i) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			--a;
			for (int j = 0; j < b; ++j) {
				int h = sc.nextInt();
				--h;
				g[h].add(a);
				++deg[a];
			}
		}
		int INF = 99999;
		int ans = 0;
		out:for (int i = 0; i < n; ++i) {
			int mi = INF;
			for (int d : deg)
				mi = Math.min(mi, d);
			for (int j = 0; j < n; ++j) {
				if (deg[j] == mi) {
					if (deg[j] == 0)
						++ans;
					else
						break out;
					deg[j] = INF;
					for (int dst : g[j])
						--deg[dst];
				}
			}
		}
		System.out.println(ans);
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}
0