結果
問題 | No.1266 7 Colors |
ユーザー | nehan_der_thal |
提出日時 | 2020-10-24 00:16:46 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,351 ms / 3,000 ms |
コード長 | 2,123 bytes |
コンパイル時間 | 211 ms |
コンパイル使用メモリ | 82,380 KB |
実行使用メモリ | 232,320 KB |
最終ジャッジ日時 | 2024-07-21 14:10:05 |
合計ジャッジ時間 | 19,571 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,608 KB |
testcase_01 | AC | 43 ms
52,608 KB |
testcase_02 | AC | 38 ms
52,352 KB |
testcase_03 | AC | 738 ms
103,760 KB |
testcase_04 | AC | 1,107 ms
175,232 KB |
testcase_05 | AC | 781 ms
109,980 KB |
testcase_06 | AC | 1,164 ms
187,664 KB |
testcase_07 | AC | 1,237 ms
203,652 KB |
testcase_08 | AC | 1,143 ms
178,104 KB |
testcase_09 | AC | 1,062 ms
152,432 KB |
testcase_10 | AC | 1,015 ms
144,096 KB |
testcase_11 | AC | 860 ms
117,272 KB |
testcase_12 | AC | 922 ms
125,672 KB |
testcase_13 | AC | 952 ms
132,936 KB |
testcase_14 | AC | 818 ms
109,312 KB |
testcase_15 | AC | 1,351 ms
208,884 KB |
testcase_16 | AC | 945 ms
127,488 KB |
testcase_17 | AC | 1,262 ms
200,772 KB |
testcase_18 | AC | 723 ms
232,320 KB |
testcase_19 | AC | 712 ms
217,000 KB |
testcase_20 | AC | 694 ms
218,800 KB |
testcase_21 | AC | 197 ms
84,480 KB |
ソースコード
class UnionFindNode: def __init__(self, group_id, parent=None, value=None): self.group_id_ = group_id self.parent_ = parent self.value = value self.rank_ = 1 self.member_num_ = 1 def is_root(self): return not self.parent_ def root(self): parent = self while not parent.is_root(): parent = parent.parent_ self.parent_ = parent return parent def find(self): root = self.root() return root.group_id_ def rank(self): root = self.root() return root.rank_ def unite(self, unite_node): root = self.root() unite_root = unite_node.root() if root.group_id_ != unite_root.group_id_: if root.rank() > unite_root.rank(): n_root, child = root, unite_root else: n_root, child = unite_root, root child.parent_ = n_root n_root.rank_ = max(n_root.rank_, child.rank_ + 1) n_root.member_num_ = n_root.member_num_ + child.member_num_ import sys;input=sys.stdin.readline N, M, Q = map(int, input().split()) nodes = [UnionFindNode(i) for i in range(N*7)] ss = [] for i in range(N): s = input().strip() ss.append([c for c in s]) n = i*7 for j in range(7): if s[j] == "1" and s[(j+1)%7] == "1": nodes[n+j].unite(nodes[n+(j+1)%7]) G = [set() for _ in range(N)] for _ in range(M): u, v = map(int, input().split()) u-=1;v-=1; G[u].add(v) G[v].add(u) for i in range(7): if ss[u][i] == "1" and ss[v][i] == "1": nodes[u*7+i].unite(nodes[v*7+i]) for _ in range(Q): a, b, c = map(int, input().split()) if a == 2: print(nodes[(b-1)*7].root().member_num_) else: b-=1 c-=1 ss[b][c] = "1" if ss[b][(c+1)%7] == "1": nodes[b*7+c].unite(nodes[b*7+(c+1)%7]) if ss[b][(c-1)%7] == "1": nodes[b*7+c].unite(nodes[b*7+(c-1)%7]) for u in G[b]: if ss[u][c] == "1": nodes[b*7+c].unite(nodes[u*7+c])