結果

問題 No.1266 7 Colors
ユーザー c-yanc-yan
提出日時 2020-10-23 23:46:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,421 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 10,984 KB
実行使用メモリ 64,284 KB
最終ジャッジ日時 2023-09-28 19:04:56
合計ジャッジ時間 19,863 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,064 KB
testcase_01 AC 17 ms
8,124 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1,268 ms
64,284 KB
testcase_19 AC 831 ms
61,092 KB
testcase_20 AC 818 ms
61,156 KB
testcase_21 AC 505 ms
14,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import setrecursionlimit, stdin
def find(parent, i):
    t = parent[i]
    if t < 0:
        return i
    t = find(parent, t)
    parent[i] = t
    return t


def unite(parent, i, j):
    i = find(parent, i)
    j = find(parent, j)
    if i == j:
        return
    parent[j] += parent[i]
    parent[i] = j
readline = stdin.readline
setrecursionlimit(10 ** 6)

N, M, Q = map(int, readline().split())
s = [readline() for _ in range(N)]
c = [tuple(map(int, x[:-1])) for x in s]

parent = [-1] * N

for _ in range(M):
    u, v = map(int, readline().split())
    u, v = u - 1, v - 1
    up = find(parent, u)
    vp = find(parent, v)
    if up != vp:
        x = tuple(c[up][i] + c[vp][i] for i in range(7))
        c[up] = x
        c[vp] = x
        unite(parent, u, v)

result = []
for _ in range(Q):
    t, x, y = map(int, readline().split())
    if t == 1:
        x, y = x - 1, y - 1
        xp = find(parent, x)
        z = 1 << (6 - y)
        a = list(c[xp])
        a[y] += 1
        c[xp] = tuple(a)
    elif t == 2:
        x = x - 1
        xp = find(parent, x)
        a = set()
        b = c[xp]
        for i in range(7):
            if b[i] == 0:
                break
            a.add(i)
        for i in range(6, -1, -1):
            if b[i] == 0:
                break
            a.add(i)
        d = 0
        for i in a:
            d += b[i]
        result.append(d)
print(*result, sep='\n')
0