結果
| 問題 |
No.2316 Freight Train
|
| コンテスト | |
| ユーザー |
ニックネーム
|
| 提出日時 | 2023-05-26 21:26:56 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 611 bytes |
| コンパイル時間 | 145 ms |
| コンパイル使用メモリ | 12,416 KB |
| 実行使用メモリ | 28,680 KB |
| 最終ジャッジ日時 | 2024-12-25 04:49:46 |
| 合計ジャッジ時間 | 44,855 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 TLE * 8 |
ソースコード
class UF:
def __init__(self,n):
self.p = [-1]*n
def f(self,x):
if self.p[x]<0: return x
else: self.p[x] = self.f(self.p[x]); return self.p[x]
def u(self,x,y):
x = self.f(x); y = self.f(y)
if x==y: return
if -self.p[x]<-self.p[y]: x,y = y,x
self.p[x] += self.p[y]; self.p[y] = x
def s(self,x,y): return self.f(x) == self.f(y)
n,q = map(int,input().split())
uf = UF(n)
for i,v in enumerate(map(int,input().split())):
if v !=-1: uf.u(i,v-1)
for _ in range(q):
a,b = map(int,input().split())
print("Yes" if uf.s(a-1,b-1) else "No")
ニックネーム