結果
問題 |
No.3093 Safe Infection
|
ユーザー |
![]() |
提出日時 | 2025-05-05 02:36:34 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,441 bytes |
コンパイル時間 | 504 ms |
コンパイル使用メモリ | 82,796 KB |
実行使用メモリ | 110,012 KB |
最終ジャッジ日時 | 2025-05-05 02:36:47 |
合計ジャッジ時間 | 12,528 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 49 WA * 22 |
ソースコード
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)] # グループ分け Nodes = [1]*(N) # 各グループのノードの数 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) #print(A) SA=[(A[i],i) for i in range(N)] SA.sort() for a,ind in SA: fi=find(ind) NOW=a flag=1 LIST=[] MAX=-1<<60 #print(fi,E[fi]) for to in E[fi]: if find(fi)==find(to): continue if 0<=A[find(to)]-NOW<=K: LIST.append(find(to)) MAX=max(MAX,A[find(to)]) x=fi 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 #assert find(ind)==x #print(E[x]) if Nodes[find(0)]==N: print("Yes") else: print("No")