提出 #71511324


ソースコード 拡げる

import sys
sys.setrecursionlimit(10 ** 6)

import numpy as np
from numba import jit, boolean, int64, float64, typeof, types, typeof, objmode
# jit = lambda func, *args, **kwargs: func



def main():
    from io import StringIO
    execute(StringIO(sample), sys.stderr)
    print("-- ^sample! --", file=sys.stderr)

    execute(sys.stdin, sys.stdout)

    if len(solve.nopython_signatures) != 1:
        raise KeyboardInterrupt("!! Unexpected: wrong use of jit !!")

def execute(src, dst):

    N, M, = map(int, src.readline().split())
    XY1d = np.fromstring("\n".join(src.readline().strip() for _ in range(M)), dtype=np.int64, sep=' ')
    Q, = map(int, src.readline().split())
    Q1d = np.fromstring("\n".join(src.readline().strip() for _ in range(Q)), dtype=np.int64, sep=' ')
    ans = solve(N, M, XY1d, Q, Q1d )
    print(*ans, sep="\n", file=dst)

sample = """\
5 6
1 2
2 3
3 1
4 5
1 4
2 5
5
1 3
2 1
2 4
1 5
2 4
"""

@jit(nopython=True, cache=True)
def solve(N, M, XY1d, Q, Q1d ):
    empty = [i for i in range(0)]
    toE1 = [empty.copy() for _n in range(N + 1) ]
    fromE1 = [empty.copy() for _n in range(N + 1) ]
    for x, y in XY1d.reshape((M,2,)):
        toE1[x].append(y)
        fromE1[y].append(x)

    ans = []
    isblack = np.zeros((N+1,) , dtype=np.bool_)
    for qty , qv in Q1d.reshape((Q,2,)):
        if qty == 1:
            whileDFS(qv , fromE1 , isblack)
        if qty == 2:
            if isblack[qv] :
                ans.append("Yes")
            else:
                ans.append("No")
    1
    return ans

@jit(nopython=True, cache=True)
def whileDFS(id_start, E, isblack):
    # visited = np.zeros(shape=len(E_ll), dtype=np.bool_)
    visited = isblack
    # 開始処理
    stack = []
    stack.append(id_start)
    while stack:
        id_now = stack.pop()
        if visited[id_now] == True:
            continue    # 調査済みチェックは本当に必要か????
        visited[id_now] = True
        # 行きがけでの処理
        # -
        for id_next in E[id_now]:
            if visited[id_next] == False:
            # if id_next not in visited:
                stack.append(id_next)
        # 末端での処理
        # -
        continue
    return None



main()

提出情報

提出日時
問題 D - Reachability Query 2
ユーザ tariaki
言語 Python (CPython 3.13.7)
得点 425
コード長 2324 Byte
結果 AC
実行時間 1181 ms
メモリ 299500 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 425 / 425
結果
AC × 1
AC × 30
セット名 テストケース
Sample sample_01.txt
All min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, sample_01.txt
ケース名 結果 実行時間 メモリ
min.txt AC 439 ms 139444 KiB
random_01.txt AC 926 ms 274788 KiB
random_02.txt AC 949 ms 274916 KiB
random_03.txt AC 634 ms 203188 KiB
random_04.txt AC 666 ms 209836 KiB
random_05.txt AC 557 ms 176856 KiB
random_06.txt AC 565 ms 175052 KiB
random_07.txt AC 580 ms 182576 KiB
random_08.txt AC 875 ms 257388 KiB
random_09.txt AC 554 ms 168144 KiB
random_10.txt AC 564 ms 168876 KiB
random_11.txt AC 635 ms 187484 KiB
random_12.txt AC 959 ms 246652 KiB
random_13.txt AC 548 ms 161752 KiB
random_14.txt AC 533 ms 159276 KiB
random_15.txt AC 686 ms 191712 KiB
random_16.txt AC 693 ms 190304 KiB
random_17.txt AC 824 ms 251836 KiB
random_18.txt AC 819 ms 268988 KiB
random_19.txt AC 538 ms 175396 KiB
random_20.txt AC 557 ms 180012 KiB
random_21.txt AC 965 ms 283068 KiB
random_22.txt AC 986 ms 283328 KiB
random_23.txt AC 821 ms 269636 KiB
random_24.txt AC 843 ms 269916 KiB
random_25.txt AC 1181 ms 283776 KiB
random_26.txt AC 1172 ms 299500 KiB
random_27.txt AC 1051 ms 281932 KiB
random_28.txt AC 825 ms 251144 KiB
sample_01.txt AC 429 ms 139852 KiB