結果

問題 No.2316 Freight Train
ユーザー cleanttedcleantted
提出日時 2023-02-19 01:09:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,279 bytes
コンパイル時間 988 ms
コンパイル使用メモリ 81,780 KB
実行使用メモリ 122,572 KB
最終ジャッジ日時 2023-10-18 13:03:28
合計ジャッジ時間 10,414 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 259 ms
122,568 KB
testcase_24 AC 289 ms
122,564 KB
testcase_25 WA -
testcase_26 AC 259 ms
121,296 KB
testcase_27 AC 219 ms
91,964 KB
testcase_28 AC 153 ms
90,908 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