Created
July 27, 2023 07:06
-
-
Save modos/591506ad019ceb19ea99a9b96abd581f to your computer and use it in GitHub Desktop.
هیتلر مخفی
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# run with pypy3 | |
import heapq | |
n, m = map(int, input().split()) | |
a = list(map(int, input().split())) | |
adj = [list() for i in range(n)] | |
for i in range(m): | |
u, v = map(int, input().split()) | |
adj[v - 1].append(u - 1) | |
adj[u - 1].append(v - 1) | |
for v in range(n): | |
p, e = a[v], 0; | |
mark = [False for i in range(n)] | |
mark[v] = True | |
seen = [False for i in range(n)] | |
seen[v] = True | |
ns = list() | |
for u in adj[v]: | |
if (not mark[u]) and (not seen[u]): | |
heapq.heappush(ns, (a[u], u)) | |
seen[u] = True | |
for i in range(n - 1): | |
u = heapq.heappop(ns)[1] | |
mark[u] = True | |
for w in adj[u]: | |
if (not mark[w]) and (not seen[w]): | |
heapq.heappush(ns, (a[w], w)) | |
seen[w] = True | |
if a[u] < p + e: | |
p += a[u] | |
else: | |
e += a[u] - (p + e) + 1 | |
p += a[u] | |
if v == n - 1: | |
print(e) | |
else: | |
print(e, end=' ') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment