結果

問題 No.1640 簡単な色塗り
ユーザー 小野寺健小野寺健
提出日時 2021-11-29 15:06:32
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,459 bytes
コンパイル時間 4,448 ms
コンパイル使用メモリ 75,496 KB
実行使用メモリ 190,324 KB
最終ジャッジ日時 2023-09-15 07:24:07
合計ジャッジ時間 79,519 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
62,620 KB
testcase_01 AC 119 ms
190,324 KB
testcase_02 AC 120 ms
60,720 KB
testcase_03 AC 117 ms
56,004 KB
testcase_04 AC 1,906 ms
97,564 KB
testcase_05 AC 1,916 ms
99,888 KB
testcase_06 AC 119 ms
56,256 KB
testcase_07 AC 119 ms
56,060 KB
testcase_08 AC 120 ms
56,016 KB
testcase_09 AC 121 ms
55,764 KB
testcase_10 AC 1,638 ms
84,532 KB
testcase_11 AC 1,489 ms
81,912 KB
testcase_12 AC 1,384 ms
82,964 KB
testcase_13 AC 1,988 ms
99,452 KB
testcase_14 AC 1,983 ms
97,688 KB
testcase_15 AC 956 ms
68,564 KB
testcase_16 AC 1,300 ms
78,820 KB
testcase_17 AC 1,853 ms
93,968 KB
testcase_18 AC 465 ms
60,064 KB
testcase_19 AC 1,361 ms
83,124 KB
testcase_20 AC 1,600 ms
82,428 KB
testcase_21 AC 1,420 ms
83,820 KB
testcase_22 AC 386 ms
60,580 KB
testcase_23 AC 1,678 ms
84,668 KB
testcase_24 AC 605 ms
65,192 KB
testcase_25 AC 1,348 ms
82,276 KB
testcase_26 AC 1,755 ms
86,256 KB
testcase_27 AC 832 ms
69,868 KB
testcase_28 AC 1,931 ms
95,856 KB
testcase_29 AC 1,786 ms
86,220 KB
testcase_30 AC 418 ms
62,160 KB
testcase_31 AC 1,758 ms
102,604 KB
testcase_32 TLE -
testcase_33 AC 1,687 ms
87,108 KB
testcase_34 AC 1,960 ms
96,864 KB
testcase_35 AC 1,344 ms
85,340 KB
testcase_36 AC 415 ms
62,908 KB
testcase_37 AC 493 ms
66,864 KB
testcase_38 AC 1,776 ms
100,860 KB
testcase_39 AC 999 ms
82,024 KB
testcase_40 AC 763 ms
73,764 KB
testcase_41 AC 1,750 ms
95,940 KB
testcase_42 AC 1,093 ms
81,512 KB
testcase_43 AC 1,244 ms
84,588 KB
testcase_44 AC 1,486 ms
84,088 KB
testcase_45 AC 761 ms
70,564 KB
testcase_46 AC 462 ms
64,260 KB
testcase_47 AC 404 ms
63,160 KB
testcase_48 TLE -
testcase_49 AC 290 ms
60,064 KB
testcase_50 AC 117 ms
55,792 KB
testcase_51 AC 117 ms
56,036 KB
testcase_52 TLE -
testcase_53 TLE -
07_evil_01.txt TLE -
07_evil_02.txt TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class No1640 {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		N = Integer.valueOf(scan.nextLine());
		G = new ArrayList<List<Integer>>();
		for (int i=0; i < 2*N; i++) {
			G.add(new ArrayList<Integer>());
		}
		match = new int[2*N];
		Arrays.fill(match, -1);
		used = new boolean[2*N];
		for (int i=0; i < N; i++) {
			String[] s = scan.nextLine().split(" ");
			add_edge(i, Integer.valueOf(s[0]) + N - 1);
			add_edge(i, Integer.valueOf(s[1]) + N - 1);
		}
		int n = bipartite_matching();
		if (n == N) {
			System.out.println("Yes");
			for (int i=0; i < N; i++) {
				System.out.println(match[i] - N + 1);
			}
		} else {
			System.out.println("No");
		}
	}
	
	private static int N;
	private static List<List<Integer>> G;
	private static int[] match;
	private static boolean[] used;
	
	private static void add_edge(int u, int v) {
		G.get(u).add(v);
		G.get(v).add(u);
	}
	
	private static boolean dfs(int v) {
		used[v] = true;
		for (int u : G.get(v)) {
			int w = match[u];
			if (w < 0 || (!used[w] && dfs(w))) {
				match[v] = u;
				match[u] = v;
				return true;
			}
		}
		return false;
	}
	
	private static int bipartite_matching() {
		int res = 0;
		for (int v=0; v < 2*N; v++) {
			if (match[v] < 0) {
				Arrays.fill(used, false);
				if (dfs(v)) {
					res++;
				}
			}
		}
		return res;
	}
}
0