結果
| 問題 |
No.1266 7 Colors
|
| コンテスト | |
| ユーザー |
sotanishy
|
| 提出日時 | 2020-10-23 22:49:23 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 802 ms / 3,000 ms |
| コード長 | 1,587 bytes |
| コンパイル時間 | 206 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 114,364 KB |
| 最終ジャッジ日時 | 2024-07-21 11:54:46 |
| 合計ジャッジ時間 | 13,929 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
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))
sotanishy