結果
問題 |
No.3093 Safe Infection
|
ユーザー |
![]() |
提出日時 | 2025-04-11 17:16:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 387 ms / 2,000 ms |
コード長 | 608 bytes |
コンパイル時間 | 347 ms |
コンパイル使用メモリ | 82,284 KB |
実行使用メモリ | 98,784 KB |
最終ジャッジ日時 | 2025-04-11 17:16:24 |
合計ジャッジ時間 | 17,504 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 70 |
ソースコード
n,m,k=map(int,input().split()) a=list(map(int,input().split())) e=[[] for i in range(n)] for _ in range(m): u,v=map(int,input().split()) u-=1 v-=1 e[u]+=[v] e[v]+=[u] r=list(range(n)) def union(x,y): rx=root(x) ry=root(y) if rx==ry: return if a[rx]<a[ry]: rx,ry=ry,rx r[ry]=rx return def root(x): p=x l=[p] while r[p]!=p: p=r[p] l+=[p] for p in l: r[p]=l[-1] return r[x] for s in sorted(list(range(n)),key=lambda i:a[i]): for t in e[s]: if 0<=a[root(s)]-a[root(t)]<=k: union(s,t) print(["No","Yes"][len(set(root(i) for i in range(n)))==1])