結果
| 問題 |
No.3093 Safe Infection
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2025-05-05 01:53:32 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,350 bytes |
| コンパイル時間 | 544 ms |
| コンパイル使用メモリ | 82,364 KB |
| 実行使用メモリ | 110,252 KB |
| 最終ジャッジ日時 | 2025-05-05 01:53:49 |
| 合計ジャッジ時間 | 15,748 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 39 WA * 32 |
ソースコード
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
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(A[find(fi)],A[find(to)])
x=find(ind)
for to in LIST:
Union(x,to)
nfi=find(x)
if nfi==x:
E[nfi]|=E[to]
else:
E[nfi]|=E[x]
x=nfi
A[x]=MAX
if Nodes[find(0)]==N:
print("Yes")
else:
print("No")
titia