結果

問題 No.1266 7 Colors
ユーザー tcltktcltk
提出日時 2021-01-21 15:00:38
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,914 bytes
コンパイル時間 2,203 ms
コンパイル使用メモリ 86,420 KB
実行使用メモリ 837,440 KB
最終ジャッジ日時 2023-08-26 01:57:41
合計ジャッジ時間 7,195 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 237 ms
83,008 KB
testcase_01 AC 233 ms
83,000 KB
testcase_02 AC 234 ms
83,012 KB
testcase_03 MLE -
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 #

#region Header
#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
from queue import PriorityQueue
import bisect
import heapq

def input():
    return sys.stdin.readline()[:-1]

sys.setrecursionlimit(1000000)
#endregion

# _INPUT = """3 2 3
# 1010000
# 1000000
# 0010000
# 1 2
# 1 3
# 2 1 0
# 1 1 2
# 2 1 0
# """
# sys.stdin = io.StringIO(_INPUT)


def dfs(G, colors, seen, city, color):
    next_colors = set([color])
    seen[city][color] = True
    i = (color + 1) % 7
    while colors[city][i] and (i not in next_colors):
        if not seen[city][i]:
            seen[city][i] = True
            next_colors.add(i)
        i = (i + 1) % 7
    i = (color - 1) % 7
    while colors[city][i] and (i not in next_colors):
        if not seen[city][i]:
            seen[city][i] = True
            next_colors.add(i)
        i = (i - 1) % 7

    n = 0
    for next_color in next_colors:
        n += 1
        for next_city in G[city]:
            if colors[next_city][next_color] and (not seen[next_city][next_color]):
                n += dfs(G, colors, seen, next_city, next_color)

    return n

def main():
    N, M, Q = map(int, input().split())
    colors = [None for _ in range(N)]
    for i in range(N):
        s = input()
        colors[i] = [(s[j] == '1') for j in range(7)]
    G = [list() for _ in range(N)]
    for _ in range(M):
        _u, _v = map(int, input().split())
        G[_u-1].append(_v-1)
        G[_v-1].append(_u-1)

    for _ in range(Q):
        t, x, y = map(int, input().split())
        if t == 1:
            colors[x-1][y-1] = True

        else:
            seen = [[False for _ in range(7)] for _ in range(N)]
            n = dfs(G, colors, seen, x-1, 0)
            print(n)

if __name__ == '__main__':
    main()
0