結果

問題 No.1640 簡単な色塗り
ユーザー wolgnikwolgnik
提出日時 2021-08-06 22:38:25
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 434 ms / 2,000 ms
コード長 1,374 bytes
コンパイル時間 539 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 109,932 KB
最終ジャッジ日時 2023-09-12 02:36:27
合計ジャッジ時間 18,245 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,172 KB
testcase_01 AC 70 ms
71,400 KB
testcase_02 AC 71 ms
71,180 KB
testcase_03 AC 72 ms
71,392 KB
testcase_04 AC 170 ms
100,128 KB
testcase_05 AC 165 ms
100,176 KB
testcase_06 AC 71 ms
71,500 KB
testcase_07 AC 71 ms
71,136 KB
testcase_08 AC 72 ms
71,608 KB
testcase_09 AC 73 ms
71,420 KB
testcase_10 AC 216 ms
92,868 KB
testcase_11 AC 190 ms
88,680 KB
testcase_12 AC 184 ms
89,832 KB
testcase_13 AC 272 ms
100,156 KB
testcase_14 AC 271 ms
99,976 KB
testcase_15 AC 166 ms
84,824 KB
testcase_16 AC 175 ms
88,176 KB
testcase_17 AC 248 ms
97,840 KB
testcase_18 AC 125 ms
78,848 KB
testcase_19 AC 187 ms
88,452 KB
testcase_20 AC 203 ms
89,732 KB
testcase_21 AC 191 ms
88,964 KB
testcase_22 AC 120 ms
78,316 KB
testcase_23 AC 221 ms
93,516 KB
testcase_24 AC 150 ms
81,736 KB
testcase_25 AC 187 ms
89,976 KB
testcase_26 AC 235 ms
94,816 KB
testcase_27 AC 166 ms
84,280 KB
testcase_28 AC 266 ms
99,288 KB
testcase_29 AC 239 ms
95,912 KB
testcase_30 AC 105 ms
80,476 KB
testcase_31 AC 200 ms
103,128 KB
testcase_32 AC 190 ms
97,424 KB
testcase_33 AC 149 ms
92,000 KB
testcase_34 AC 185 ms
99,948 KB
testcase_35 AC 139 ms
91,304 KB
testcase_36 AC 110 ms
80,500 KB
testcase_37 AC 111 ms
81,452 KB
testcase_38 AC 182 ms
98,992 KB
testcase_39 AC 126 ms
86,536 KB
testcase_40 AC 121 ms
85,308 KB
testcase_41 AC 183 ms
97,268 KB
testcase_42 AC 132 ms
85,912 KB
testcase_43 AC 143 ms
89,108 KB
testcase_44 AC 134 ms
86,756 KB
testcase_45 AC 126 ms
86,024 KB
testcase_46 AC 107 ms
80,296 KB
testcase_47 AC 104 ms
79,256 KB
testcase_48 AC 205 ms
100,024 KB
testcase_49 AC 96 ms
77,588 KB
testcase_50 AC 71 ms
71,556 KB
testcase_51 AC 72 ms
71,252 KB
testcase_52 AC 231 ms
108,132 KB
testcase_53 AC 434 ms
109,932 KB
07_evil_01.txt AC 439 ms
127,856 KB
07_evil_02.txt AC 618 ms
158,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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")
0