結果

問題 No.2316 Freight Train
ユーザー cleanttedcleantted
提出日時 2023-02-19 01:10:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 361 ms / 2,000 ms
コード長 1,279 bytes
コンパイル時間 751 ms
コンパイル使用メモリ 81,580 KB
実行使用メモリ 126,580 KB
最終ジャッジ日時 2023-10-18 13:02:44
合計ジャッジ時間 11,344 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 154 ms
90,768 KB
testcase_01 AC 147 ms
90,772 KB
testcase_02 AC 150 ms
90,768 KB
testcase_03 AC 361 ms
125,740 KB
testcase_04 AC 254 ms
106,132 KB
testcase_05 AC 249 ms
106,356 KB
testcase_06 AC 193 ms
92,228 KB
testcase_07 AC 265 ms
96,628 KB
testcase_08 AC 286 ms
123,744 KB
testcase_09 AC 285 ms
111,064 KB
testcase_10 AC 285 ms
106,212 KB
testcase_11 AC 308 ms
119,260 KB
testcase_12 AC 294 ms
115,300 KB
testcase_13 AC 322 ms
126,312 KB
testcase_14 AC 324 ms
122,956 KB
testcase_15 AC 330 ms
122,952 KB
testcase_16 AC 329 ms
123,220 KB
testcase_17 AC 320 ms
126,580 KB
testcase_18 AC 330 ms
122,956 KB
testcase_19 AC 325 ms
123,220 KB
testcase_20 AC 337 ms
122,956 KB
testcase_21 AC 333 ms
122,956 KB
testcase_22 AC 331 ms
122,960 KB
testcase_23 AC 260 ms
122,424 KB
testcase_24 AC 279 ms
122,428 KB
testcase_25 AC 267 ms
121,168 KB
testcase_26 AC 261 ms
121,160 KB
testcase_27 AC 214 ms
91,856 KB
testcase_28 AC 151 ms
90,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque, Counter
from math import gcd, log10, pi, sqrt, ceil
from bisect import bisect, bisect_left, bisect_right, insort
from typing import Iterable, TypeVar, Union, Tuple, Iterator, List
import copy
import heapq
import itertools
import math
import random
from fractions import Fraction
from functools import lru_cache, partial, cmp_to_key
import operator
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
mod = 998244353
INF = 1 << 61
DIFF = 10 ** -9
DX = [1, 0, -1, 0, 1, 1, -1, -1]
DY = [0, 1, 0, -1, 1, -1, 1, -1]

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for _ in range(N)]


def main():
    N, Q = read_values() 
    P = read_list()

    top = [-1] * N
    def dfs(i):
        if top[i] != -1:
            return

        if P[i] == -1:
            top[i] = i
            return

        p = P[i] - 1
        dfs(p)
        top[i] = top[p]

    for i in range(N):
        if top[i] != -1:
            continue
        dfs(i)

    for _ in range(Q):
        a, b = read_index()
        print("Yes" if top[a] == top[b] else "No")


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