結果
問題 | No.1266 7 Colors |
ユーザー | sotanishy |
提出日時 | 2020-10-23 22:49:23 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 853 ms / 3,000 ms |
コード長 | 1,587 bytes |
コンパイル時間 | 505 ms |
コンパイル使用メモリ | 86,812 KB |
実行使用メモリ | 114,728 KB |
最終ジャッジ日時 | 2023-09-28 17:14:32 |
合計ジャッジ時間 | 16,054 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 74 ms
71,332 KB |
testcase_01 | AC | 75 ms
71,288 KB |
testcase_02 | AC | 75 ms
71,524 KB |
testcase_03 | AC | 661 ms
88,668 KB |
testcase_04 | AC | 776 ms
101,444 KB |
testcase_05 | AC | 690 ms
90,364 KB |
testcase_06 | AC | 794 ms
105,256 KB |
testcase_07 | AC | 812 ms
108,232 KB |
testcase_08 | AC | 772 ms
102,548 KB |
testcase_09 | AC | 752 ms
97,376 KB |
testcase_10 | AC | 755 ms
95,864 KB |
testcase_11 | AC | 720 ms
90,884 KB |
testcase_12 | AC | 752 ms
92,892 KB |
testcase_13 | AC | 755 ms
94,188 KB |
testcase_14 | AC | 691 ms
89,432 KB |
testcase_15 | AC | 852 ms
109,776 KB |
testcase_16 | AC | 750 ms
93,996 KB |
testcase_17 | AC | 853 ms
108,916 KB |
testcase_18 | AC | 529 ms
114,728 KB |
testcase_19 | AC | 546 ms
108,544 KB |
testcase_20 | AC | 543 ms
108,288 KB |
testcase_21 | AC | 231 ms
81,736 KB |
ソースコード
import sys input = sys.stdin.readline class UnionFind: def __init__(self, N): self.par = [-1] * N def find(self, x): r = x while self.par[r] >= 0: r = self.par[r] while x != r: tmp = self.par[x] self.par[x] = r x = tmp return r def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.par[x] > self.par[y]: x, y = y, x self.par[x] += self.par[y] self.par[y] = x 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(map(int, input().rstrip())) for _ in range(N)] G = [[] for _ in range(N)] uf = UnionFind(7 * N) for i in range(N): for j in range(7): if s[i][j] and s[i][(j + 1) % 7]: uf.unite(7 * i + j, 7 * i + (j + 1) % 7) for _ in range(M): u, v = map(lambda x: int(x) - 1, input().split()) G[u].append(v) G[v].append(u) for j in range(7): if s[u][j] and s[v][j]: uf.unite(7 * u + j, 7 * v + j) for _ in range(Q): t, x, y = map(int, input().split()) x -= 1 y -= 1 if t == 1: s[x][y] = 1 if s[x][(y - 1) % 7]: uf.unite(7*x + (y - 1) % 7, 7*x + y) if s[x][(y + 1) % 7]: uf.unite(7*x + y, 7*x + (y + 1) % 7) for v in G[x]: if s[v][y]: uf.unite(7*x + y, 7*v + y) else: print(uf.size(7*x))