結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 149 ms
90,820 KB
testcase_01 AC 153 ms
90,820 KB
testcase_02 AC 150 ms
90,824 KB
testcase_03 AC 299 ms
122,048 KB
testcase_04 AC 229 ms
105,768 KB
testcase_05 AC 224 ms
105,752 KB
testcase_06 AC 186 ms
91,920 KB
testcase_07 AC 248 ms
96,316 KB
testcase_08 AC 262 ms
122,308 KB
testcase_09 AC 260 ms
110,360 KB
testcase_10 AC 255 ms
105,816 KB
testcase_11 AC 267 ms
118,880 KB
testcase_12 AC 275 ms
114,656 KB
testcase_13 AC 302 ms
122,308 KB
testcase_14 AC 303 ms
122,312 KB
testcase_15 AC 309 ms
122,312 KB
testcase_16 AC 302 ms
122,308 KB
testcase_17 AC 304 ms
122,312 KB
testcase_18 AC 304 ms
122,312 KB
testcase_19 AC 298 ms
122,316 KB
testcase_20 AC 297 ms
122,316 KB
testcase_21 AC 306 ms
122,312 KB
testcase_22 AC 305 ms
122,308 KB
testcase_23 AC 266 ms
122,312 KB
testcase_24 AC 289 ms
122,316 KB
testcase_25 AC 276 ms
121,040 KB
testcase_26 AC 259 ms
121,044 KB
testcase_27 AC 212 ms
91,852 KB
testcase_28 AC 153 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
    for i, p in enumerate(P):
        if p == -1:
            top[i] = i
        else:
            top[i] = p - 1

    for _ in range(N.bit_length() + 1):
        for i in range(N):
            top[i] = top[top[i]]

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


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