結果
問題 | No.1266 7 Colors |
ユーザー | NatsubiSogan |
提出日時 | 2020-10-24 00:49:49 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,436 ms / 3,000 ms |
コード長 | 1,598 bytes |
コンパイル時間 | 294 ms |
コンパイル使用メモリ | 86,900 KB |
実行使用メモリ | 135,488 KB |
最終ジャッジ日時 | 2023-09-28 19:50:04 |
合計ジャッジ時間 | 21,366 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 74 ms
71,264 KB |
testcase_01 | AC | 75 ms
71,384 KB |
testcase_02 | AC | 76 ms
71,404 KB |
testcase_03 | AC | 843 ms
92,060 KB |
testcase_04 | AC | 1,436 ms
122,044 KB |
testcase_05 | AC | 879 ms
93,772 KB |
testcase_06 | AC | 1,280 ms
125,836 KB |
testcase_07 | AC | 1,349 ms
133,404 KB |
testcase_08 | AC | 1,288 ms
122,388 KB |
testcase_09 | AC | 1,198 ms
112,432 KB |
testcase_10 | AC | 1,139 ms
109,672 KB |
testcase_11 | AC | 922 ms
98,408 KB |
testcase_12 | AC | 1,047 ms
103,580 KB |
testcase_13 | AC | 1,063 ms
104,604 KB |
testcase_14 | AC | 885 ms
93,300 KB |
testcase_15 | AC | 1,365 ms
135,488 KB |
testcase_16 | AC | 1,057 ms
101,952 KB |
testcase_17 | AC | 1,292 ms
129,596 KB |
testcase_18 | AC | 581 ms
132,508 KB |
testcase_19 | AC | 424 ms
129,696 KB |
testcase_20 | AC | 426 ms
130,064 KB |
testcase_21 | AC | 436 ms
82,168 KB |
ソースコード
#Union-Find class UnionFind(): def __init__(self, n): self.n = n self.par = [-1] * n def find(self, x): if self.par[x] < 0: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x, y): p = self.find(x) q = self.find(y) if p == q: return None if self.par[p] > self.par[q]: p, q = q, p self.par[p] += self.par[q] self.par[q] = p def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.par[self.find(x)] n, m, q = map(int, input().split()) s = [list(input()) for i in range(n)] UF = UnionFind(n * 7) for i in range(n): for j in range(7): if s[i][j] == "1" and s[i][(j + 1) % 7] == "1": UF.unite(i * 7 + j, i * 7 + (j + 1) % 7) edges = [[] for i in range(n)] for i in range(m): x, y = map(int, input().split()) x -= 1 y -= 1 edges[x].append(y) edges[y].append(x) for j in range(7): if s[x][j] == "1" and s[y][j] == "1": UF.unite(x * 7 + j, y * 7 + j) for i in range(q): qu, a, b = map(int, input().split()) a -= 1 b -= 1 if qu == 1: s[a][b] = "1" if s[a][(b - 1) % 7] == "1": UF.unite(a * 7 + (b - 1) % 7, a * 7 + b) if s[a][(b + 1) % 7] == "1": UF.unite(a * 7 + (b + 1) % 7, a * 7 + b) for v in edges[a]: if s[v][b] == "1": UF.unite(a * 7 + b, v * 7 + b) else: print(UF.size(a * 7))