結果
問題 | No.1266 7 Colors |
ユーザー | Coki628 |
提出日時 | 2020-12-06 02:05:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,418 ms / 3,000 ms |
コード長 | 3,205 bytes |
コンパイル時間 | 189 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 180,480 KB |
最終ジャッジ日時 | 2024-09-16 15:34:57 |
合計ジャッジ時間 | 21,806 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
52,864 KB |
testcase_01 | AC | 43 ms
52,992 KB |
testcase_02 | AC | 44 ms
52,992 KB |
testcase_03 | AC | 952 ms
115,584 KB |
testcase_04 | AC | 1,253 ms
159,104 KB |
testcase_05 | AC | 924 ms
118,528 KB |
testcase_06 | AC | 1,266 ms
167,424 KB |
testcase_07 | AC | 1,352 ms
178,176 KB |
testcase_08 | AC | 1,266 ms
161,408 KB |
testcase_09 | AC | 1,158 ms
145,152 KB |
testcase_10 | AC | 1,138 ms
139,520 KB |
testcase_11 | AC | 974 ms
123,264 KB |
testcase_12 | AC | 1,041 ms
128,256 KB |
testcase_13 | AC | 1,102 ms
132,992 KB |
testcase_14 | AC | 1,019 ms
118,144 KB |
testcase_15 | AC | 1,418 ms
180,480 KB |
testcase_16 | AC | 1,141 ms
130,688 KB |
testcase_17 | AC | 1,378 ms
175,616 KB |
testcase_18 | AC | 649 ms
142,592 KB |
testcase_19 | AC | 739 ms
149,632 KB |
testcase_20 | AC | 729 ms
150,144 KB |
testcase_21 | AC | 282 ms
102,784 KB |
ソースコード
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for k in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10**9) INF = 10**19 MOD = 10**9 + 7 EPS = 10**-10 class UnionFind: """ Union-Find木 """ def __init__(self, n): self.n = n self.par = [i for i in range(n)] self.rank = [0] * n self.size = [1] * n self.tree = [True] * n self.grpcnt = n def find(self, x): """ 根の検索(グループ番号の取得) """ t = [] while self.par[x] != x: t.append(x) x = self.par[x] for i in t: self.par[i] = x return self.par[x] def union(self, x, y): """ 併合 """ x = self.find(x) y = self.find(y) if x == y: self.tree[x] = False return if not self.tree[x] or not self.tree[y]: self.tree[x] = self.tree[y] = False self.grpcnt -= 1 if self.rank[x] < self.rank[y]: self.par[x] = y self.size[y] += self.size[x] else: self.par[y] = x self.size[x] += self.size[y] if self.rank[x] == self.rank[y]: self.rank[x] += 1 def is_same(self, x, y): """ 同じ集合に属するか判定 """ return self.find(x) == self.find(y) def get_size(self, x=None): if x is not None: """ あるノードの属する集合のノード数 """ return self.size[self.find(x)] else: """ 集合の数 """ return self.grpcnt def is_tree(self, x): """ 木かどうかの判定 """ return self.tree[self.find(x)] def get_roots(self): """ 全ての根を取得 """ return set([self.find(i) for i in range(self.n)]) N, M, Q = MAP() L = 7 uf = UnionFind(N*L) C = [[]] * N for i in range(N): C[i] = list(map(int, input())) for j in range(L): if C[i][j] and C[i][(j+1)%L]: uf.union(i*L+j, i*L+(j+1)%L) nodes = [[[] for j in range(7)] for i in range(N)] for i in range(M): u, v = MAP() u -= 1; v -= 1 for j in range(L): if C[u][j] and C[v][j]: uf.union(u*L+j, v*L+j) else: nodes[u][j].append(v) nodes[v][j].append(u) for _ in range(Q): op, x, c = MAP() x -= 1; c -= 1 if op == 1: C[x][c] = 1 if C[x][(c-1)%L]: uf.union(x*L+c, x*L+(c-1)%L) if C[x][(c+1)%L]: uf.union(x*L+c, x*L+(c+1)%L) for v in nodes[x][c]: if C[v][c]: uf.union(x*L+c, v*L+c) else: res = uf.get_size(x*L) print(res)