結果

問題 No.1266 7 Colors
ユーザー terasaterasa
提出日時 2022-06-11 15:58:52
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 2,557 bytes
コンパイル時間 363 ms
コンパイル使用メモリ 81,852 KB
実行使用メモリ 94,344 KB
最終ジャッジ日時 2023-10-22 01:28:50
合計ジャッジ時間 6,618 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import sys
import pypyjit
import itertools
import heapq
import math
from collections import deque, defaultdict
import bisect

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
pypyjit.set_param('max_unroll_recursion=-1')


def index_lt(a, x):
    'return largest index s.t. A[i] < x or -1 if it does not exist'
    return bisect.bisect_left(a, x) - 1


def index_le(a, x):
    'return largest index s.t. A[i] <= x or -1 if it does not exist'
    return bisect.bisect_right(a, x) - 1


def index_gt(a, x):
    'return smallest index s.t. A[i] > x or len(a) if it does not exist'
    return bisect.bisect_right(a, x)


def index_ge(a, x):
    'return smallest index s.t. A[i] >= x or len(a) if it does not exist'
    return bisect.bisect_left(a, x)


class UnionFind:
    def __init__(self, N):
        self.N = N
        self.par = [-1] * N

    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return False
        if x > y:
            x, y = y, x

        self.par[x] += self.par[y]
        self.par[y] = x
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.par[self.find(x)]

    def roots(self):
        return [i for i in range(self.N) if self.par[i] < 0]

    def members(self, x):
        p = self.find(x)
        return [i for i in range(self.N) if self.find(i) == p]


def h(i, j):
    return i * N + j


N, M, Q = map(int, input().split())
S = [[int(c) for c in input()[:-1]] for _ in range(N)]
uf = UnionFind(7 * N)
A = list(range(7))
B = list(range(1, 7)) + [0]
for i in range(N):
    s = S[i]
    for a, b in zip(A, B):
        if s[a] * s[b] > 0:
            uf.unite(h(i, a), h(i, b))

E = [[] for _ in range(N)]
for _ in range(M):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    E[u].append(v)
    E[v].append(u)
    for j in range(7):
        if S[u][j] * S[v][j] > 0:
            uf.unite(h(u, j), h(v, j))

for _ in range(Q):
    t, x, y = map(int, input().split())
    x -= 1
    y -= 1
    if t == 1:
        S[x][y] = 1
        pre = (y - 1) % 7
        nxt = (y + 1) % 7
        for j in [pre, nxt]:
            if S[x][j] > 0:
                uf.unite(h(x, y), h(x, j))
        for d in E[x]:
            if S[d][y]:
                uf.unite(h(x, y), h(d, y))
    else:
        print(uf.size(h(x, 0)))
0