結果
問題 |
No.3093 Safe Infection
|
ユーザー |
![]() |
提出日時 | 2025-05-05 02:04:35 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,381 bytes |
コンパイル時間 | 723 ms |
コンパイル使用メモリ | 82,648 KB |
実行使用メモリ | 277,392 KB |
最終ジャッジ日時 | 2025-05-05 02:04:46 |
合計ジャッジ時間 | 10,756 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 42 WA * 2 TLE * 1 -- * 26 |
ソースコード
import sys input = sys.stdin.readline N,M,K=map(int,input().split()) A=list(map(int,input().split())) E=[set() for i in range(N)] for i in range(M): x,y=map(int,input().split()) x-=1 y-=1 E[x].add(y) E[y].add(x) # UnionFind Group = [i for i in range(N+1)] # グループ分け Nodes = [1]*(N+1) # 各グループのノードの数 def find(x): while Group[x] != x: x=Group[x] return x def Union(x,y): if find(x) != find(y): if Nodes[find(x)] < Nodes[find(y)]: Nodes[find(y)] += Nodes[find(x)] Nodes[find(x)] = 0 Group[find(x)] = find(y) else: Nodes[find(x)] += Nodes[find(y)] Nodes[find(y)] = 0 Group[find(y)] = find(x) SA=[(A[i],i) for i in range(N)] SA.sort() for a,ind in SA: fi=find(ind) flag=1 LIST=[] MAX=-1<<60 for to in E[fi]: if find(fi)==find(to): continue if abs(A[find(fi)]-A[find(to)])<=K: LIST.append(find(to)) MAX=max(MAX,A[find(fi)],A[find(to)]) x=find(ind) for to in LIST: Union(x,to) nfi=find(x) if len(E[to])<len(E[x]): E[nfi]=E[x]|E[to] else: E[nfi]=E[to]|E[x] x=nfi A[x]=MAX if Nodes[find(0)]==N: print("Yes") else: print("No")