結果
問題 | No.3056 Disconnected Coloring |
ユーザー |
![]() |
提出日時 | 2025-03-14 22:05:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 638 ms / 2,000 ms |
コード長 | 2,374 bytes |
コンパイル時間 | 390 ms |
コンパイル使用メモリ | 82,888 KB |
実行使用メモリ | 137,044 KB |
最終ジャッジ日時 | 2025-03-14 22:05:43 |
合計ジャッジ時間 | 15,822 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 34 |
ソースコード
import sys# sys.setrecursionlimit(200005)# sys.set_int_max_str_digits(200005)int1 = lambda x: int(x)-1pDB = lambda *x: print(*x, end="\n", file=sys.stderr)p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)def II(): return int(sys.stdin.readline())def LI(): return list(map(int, sys.stdin.readline().split()))def LLI(rows_number): return [LI() for _ in range(rows_number)]def LI1(): return list(map(int1, sys.stdin.readline().split()))def LLI1(rows_number): return [LI1() for _ in range(rows_number)]def SI(): return sys.stdin.readline().rstrip()# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]# inf = -1-(-1 << 31)inf = -1-(-1 << 62)# md = 10**9+7md = 998244353class UnionFind:def __init__(self, n):self._tree = [-1]*n# number of connected componentself.cnt = ndef root(self, u):stack = []while self._tree[u] >= 0:stack.append(u)u = self._tree[u]for v in stack: self._tree[v] = ureturn udef same(self, u, v):return self.root(u) == self.root(v)def merge(self, u, v):u, v = self.root(u), self.root(v)if u == v: return Falseif self._tree[u] > self._tree[v]: u, v = v, uself._tree[u] += self._tree[v]self._tree[v] = uself.cnt -= 1return True# size of connected componentdef size(self, u):return -self._tree[self.root(u)]n,m=LI()to=[[] for _ in range(n)]uv=[]for i in range(m):u,v=LI1()to[u].append((v,i))to[v].append((u,i))uv.append((u,v))for v,i in to[0]:if v==n-1:print(-1)exit()if m&1:print(-1)exit()cnt=[m//2,m//2]ans=[-1]*mroot = 0c = 0uf = UnionFind(n)for u, v in uv:if u == root or v == root: continueuf.merge(u, v)for v, i in to[root]:if uf.same(v, n-1-root):ans[i] = ccnt[c] -= 1root = n-1c = 1uf = UnionFind(n)for u, v in uv:if u == root or v == root: continueuf.merge(u, v)for v, i in to[root]:if uf.same(v, n-1-root):ans[i] = ccnt[c] -= 1for i in range(m):if ans[i]==-1:if cnt[0]:ans[i]=0cnt[0]-=1else:ans[i]=1print("".join("RB"[c] for c in ans))