結果
問題 | No.1640 簡単な色塗り |
ユーザー | wolgnik |
提出日時 | 2021-08-06 22:38:25 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 282 ms / 2,000 ms |
コード長 | 1,374 bytes |
コンパイル時間 | 129 ms |
コンパイル使用メモリ | 82,448 KB |
実行使用メモリ | 106,288 KB |
最終ジャッジ日時 | 2024-06-29 15:40:44 |
合計ジャッジ時間 | 13,849 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
52,352 KB |
testcase_01 | AC | 37 ms
52,612 KB |
testcase_02 | AC | 34 ms
52,352 KB |
testcase_03 | AC | 33 ms
52,480 KB |
testcase_04 | AC | 120 ms
99,568 KB |
testcase_05 | AC | 120 ms
99,316 KB |
testcase_06 | AC | 38 ms
52,608 KB |
testcase_07 | AC | 33 ms
52,200 KB |
testcase_08 | AC | 34 ms
52,480 KB |
testcase_09 | AC | 36 ms
52,352 KB |
testcase_10 | AC | 156 ms
89,680 KB |
testcase_11 | AC | 132 ms
90,236 KB |
testcase_12 | AC | 136 ms
87,644 KB |
testcase_13 | AC | 181 ms
99,072 KB |
testcase_14 | AC | 177 ms
98,692 KB |
testcase_15 | AC | 110 ms
83,712 KB |
testcase_16 | AC | 120 ms
85,744 KB |
testcase_17 | AC | 174 ms
96,668 KB |
testcase_18 | AC | 80 ms
77,172 KB |
testcase_19 | AC | 123 ms
85,916 KB |
testcase_20 | AC | 138 ms
90,388 KB |
testcase_21 | AC | 147 ms
89,568 KB |
testcase_22 | AC | 80 ms
77,096 KB |
testcase_23 | AC | 153 ms
90,716 KB |
testcase_24 | AC | 98 ms
80,896 KB |
testcase_25 | AC | 134 ms
88,256 KB |
testcase_26 | AC | 174 ms
94,244 KB |
testcase_27 | AC | 122 ms
83,260 KB |
testcase_28 | AC | 191 ms
98,416 KB |
testcase_29 | AC | 158 ms
93,836 KB |
testcase_30 | AC | 66 ms
78,976 KB |
testcase_31 | AC | 132 ms
100,468 KB |
testcase_32 | AC | 121 ms
97,792 KB |
testcase_33 | AC | 95 ms
89,300 KB |
testcase_34 | AC | 115 ms
100,148 KB |
testcase_35 | AC | 91 ms
88,916 KB |
testcase_36 | AC | 69 ms
78,976 KB |
testcase_37 | AC | 68 ms
80,384 KB |
testcase_38 | AC | 118 ms
97,860 KB |
testcase_39 | AC | 83 ms
85,516 KB |
testcase_40 | AC | 76 ms
84,908 KB |
testcase_41 | AC | 114 ms
100,608 KB |
testcase_42 | AC | 82 ms
85,120 KB |
testcase_43 | AC | 95 ms
88,320 KB |
testcase_44 | AC | 86 ms
86,400 KB |
testcase_45 | AC | 81 ms
85,504 KB |
testcase_46 | AC | 69 ms
79,616 KB |
testcase_47 | AC | 67 ms
77,696 KB |
testcase_48 | AC | 136 ms
97,920 KB |
testcase_49 | AC | 55 ms
72,704 KB |
testcase_50 | AC | 31 ms
52,480 KB |
testcase_51 | AC | 32 ms
51,968 KB |
testcase_52 | AC | 160 ms
105,392 KB |
testcase_53 | AC | 282 ms
106,288 KB |
07_evil_01.txt | AC | 318 ms
125,892 KB |
07_evil_02.txt | AC | 442 ms
157,324 KB |
ソースコード
import sys input = sys.stdin.readline N = int(input()) class BipartiteMatching: def __init__(self, n, m): self._n = n self._m = m self._to = [[] for _ in range(n)] def add_edge(self, a, b): self._to[a].append(b) def solve(self): n, m, to = self._n, self._m, self._to pre = [-1] * n root = [-1] * n p = [-1] * n q = [-1] * m upd = True while upd: upd = False s = [] s_front = 0 for i in range(n): if p[i] == -1: root[i] = i s.append(i) while s_front < len(s): v = s[s_front] s_front += 1 if p[root[v]] != -1: continue for u in to[v]: if q[u] == -1: while u != -1: q[u] = v p[v], u = u, p[v] v = pre[v] upd = True break u = q[u] if pre[u] != -1: continue pre[u] = v root[u] = root[v] s.append(u) if upd: for i in range(n): pre[i] = -1 root[i] = -1 return [(v, p[v]) for v in range(n) if p[v] != -1] dinic = BipartiteMatching(N, N) for i in range(N): u, v = map(int, input().split()) u -= 1 v -= 1 dinic.add_edge(i, u) dinic.add_edge(i, v) flow = dinic.solve() if len(flow) == N: print("Yes") for _, x in flow: print(x + 1) else: print("No")