結果
| 問題 |
No.3093 Safe Infection
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2025-04-28 01:14:51 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,474 bytes |
| コンパイル時間 | 530 ms |
| コンパイル使用メモリ | 82,372 KB |
| 実行使用メモリ | 110,460 KB |
| 最終ジャッジ日時 | 2025-04-28 01:15:06 |
| 合計ジャッジ時間 | 14,410 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 WA * 36 TLE * 1 -- * 27 |
ソースコード
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[:-1]:
fi=find(ind)
flag=0
LIST=[fi]
MAX=a
for to in E[fi]:
#print(fi,to)
if abs(A[find(to)]-A[fi])<=K:
flag=1
MAX=max(MAX,A[find(to)])
Union(fi,to)
LIST.append(to)
MAX=max(MAX,A[find(to)])
#print(a,ind,MAX)
if flag==0:
print("No")
exit()
ff=find(fi)
TOLIST=set()
for x in LIST:
for to in E[x]:
if find(to)!=find(ind):
E[to].add(fi)
TOLIST.add(to)
E[ff]=TOLIST
A[ff]=MAX
print("Yes")
titia