結果

問題 No.2316 Freight Train
ユーザー cleanttedcleantted
提出日時 2023-02-19 01:07:32
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,188 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 81,876 KB
実行使用メモリ 209,812 KB
最終ジャッジ日時 2023-10-18 13:02:17
合計ジャッジ時間 8,045 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 152 ms
91,056 KB
testcase_01 AC 153 ms
90,972 KB
testcase_02 AC 150 ms
90,972 KB
testcase_03 TLE -
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 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

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 P[i] == -1:
            top[i] = i
            return

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

    for i in range(N):
        dfs(i)

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


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