結果

問題 No.1266 7 Colors
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2020-10-23 23:57:53
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,473 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 86,748 KB
実行使用メモリ 279,232 KB
最終ジャッジ日時 2023-09-28 19:17:31
合計ジャッジ時間 9,230 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

class Unionfind:
     
    def __init__(self,n):
        self.uf = [-1]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]

n,m,q = map(int,input().split())
S = [list(input()) for i in range(n)]
e = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    e[a].append(b)
    e[b].append(a)
Q = [tuple(map(int,input().split())) for i in range(q)]

uf = Unionfind(n*7)
used = [0]*n

from collections import deque

def connect(x,y):
    for i in range(7):
        if S[x][i] == "1" and S[y][i] == "1":
            uf.union(7*x+i,7*y+i)
    
for i in range(n):
    if used[i]:
        continue
    q = deque([i])
    while q:
        now = q.popleft()
        for nex in e[now]:
            connect(now,nex)
            used[nex] = 1
            q.append(nex)

for i,j,k in Q:
    if i == 2:
        print(uf.size(0))
    else:
        S[j][k-1] = "1"
        for nex in e[j]:
            connect(nex,j)
            
0