結果
問題 | No.1266 7 Colors |
ユーザー |
![]() |
提出日時 | 2020-10-23 23:14:31 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,003 ms / 3,000 ms |
コード長 | 1,644 bytes |
コンパイル時間 | 761 ms |
コンパイル使用メモリ | 82,516 KB |
実行使用メモリ | 124,924 KB |
最終ジャッジ日時 | 2024-07-21 13:06:02 |
合計ジャッジ時間 | 15,529 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
import sysread=sys.stdin.readreadlines=sys.stdin.readlinesinput=sys.stdin.readlineN, M, Q = map(int, input().split())S = [list(map(int, input().rstrip())) for _ in [0]*N]class UnionFind:def __init__(self, n=0):self.d = [-1]*nself.u = ndef root(self, x):if self.d[x] < 0:return xself.d[x] = self.root(self.d[x])return self.d[x]def unite(self, x, y):x, y = self.root(x), self.root(y)if x == y:return Falseif x > y:x, y = y, xself.d[x] += self.d[y]self.d[y] = xself.u -= 1return Truedef same(self, x, y):return self.root(x) == self.root(y)def size(self, x):return -self.d[self.root(x)]def num_union(self):return self.uuf = UnionFind(N*7)for i in range(N):for c in range(7):if S[i][c] and S[i][c-1]:uf.unite(i*7+c, i*7+(c-1)%7)G = [[] for _ in range(N)]for _ in [0]*M:a, b = map(int, input().split())a -= 1; b -= 1G[a].append(b)G[b].append(a)for c in range(7):if S[a][c] == 0 or S[b][c] == 0: continueuf.unite(a*7+c, b*7+c)ans = []for line in readlines():k, x, c = map(int, line.split())x -= 1; c -= 1if k == 1:S[x][c] = 1for v in G[x]:if S[v][c] == 0: continueuf.unite(x*7+c, v*7+c)if S[x][(c+1)%7]:uf.unite(x*7+c, x*7+(c+1)%7)if S[x][c-1]:uf.unite(x*7+c, x*7+(c-1)%7)else:ans.append(uf.size(x*7))print('\n'.join(map(str, ans)))