結果
| 問題 |
No.1266 7 Colors
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2020-10-23 23:46:58 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,820 bytes |
| コンパイル時間 | 223 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 129,112 KB |
| 最終ジャッジ日時 | 2024-07-21 13:49:14 |
| 合計ジャッジ時間 | 35,141 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 TLE * 1 |
ソースコード
N,M,Q=map(int,input().split())
ANS=[[0]*7 for i in range(N)]
S=[list(map(int,list(input().strip()))) for i in range(N)]
E=[[] for i in range(N)]
for i in range(M):
x,y=map(int,input().split())
x-=1
y-=1
E[x].append(y)
E[y].append(x)
# UnionFind
Group = [i for i in range(N*7)] # グループ分け
Nodes = [1]*(N*7) # 各グループのノードの数
def find(x):
while Group[x] != x:
x=Group[x]
return x
def Union(x,y):
if find(x) != find(y):
if Nodes[find(x)] < Nodes[find(y)]:
Nodes[find(y)] += Nodes[find(x)]
Nodes[find(x)] = 0
Group[find(x)] = find(y)
else:
Nodes[find(x)] += Nodes[find(y)]
Nodes[find(y)] = 0
Group[find(y)] = find(x)
for i in range(N):
for j in range(7):
if S[i][j-1]==1 and S[i][j]==1:
Union(i*7+(j-1)%7,i*7+j)
for i in range(N):
for to in E[i]:
for j in range(7):
if S[i][j]==1 and S[to][j]==1:
Union(i*7+j,to*7+j)
for i in range(Q):
q,x,y=map(int,input().split())
if q==1:
x-=1
y-=1
S[x][y]=1
Q=[x*7+y]
while Q:
town=Q.pop()
x,y=divmod(town,7)
town=find(town)
if S[x][(y+1)%7]==1 and find(x*7+(y+1)%7)!=town:
Union(x*7+y,x*7+(y+1)%7)
Q.append(x*7+(y+1)%7)
if S[x][(y-1)%7]==1 and find(x*7+(y-1)%7)!=town:
Union(x*7+y,x*7+(y-1)%7)
Q.append(x*7+(y-1)%7)
for to in E[x]:
if S[to][y]==1 and find(to*7+y)!=town:
Union(x*7+y,to*7+y)
Q.append(to*7+y)
else:
x-=1
print(Nodes[find(x*7)])
titia