Submission #31709235
Source Code Expand
Copy
from collections import dequeimport heapq# 入力n, m, k, s = map(int, input().split())p, q = map(int, input().split())c = [0] * kfor i in range(k):c[i] = int(input()) - 1e = [[] for i in range(n)]for i in range(m):a, b = map(int, input().split())e[a - 1].append(b - 1)e[b - 1].append(a - 1)# 幅優先探索 (危険な町の判定)dist = [10 ** 9] * nque = deque()for c_i in c:dist[c_i] = 0que.append(c_i)
from collections import deque import heapq # 入力 n, m, k, s = map(int, input().split()) p, q = map(int, input().split()) c = [0] * k for i in range(k): c[i] = int(input()) - 1 e = [[] for i in range(n)] for i in range(m): a, b = map(int, input().split()) e[a - 1].append(b - 1) e[b - 1].append(a - 1) # 幅優先探索 (危険な町の判定) dist = [10 ** 9] * n que = deque() for c_i in c: dist[c_i] = 0 que.append(c_i) while len(que) != 0: v = que.popleft() for u in e[v]: if dist[u] == 10 ** 9: dist[u] = dist[v] + 1 que.append(u) # ダイクストラ法 cost = [10 ** 18] * n que = [] cost[0] = 0 heapq.heappush(que, [0, 0]) while len(que) != 0: d, v = heapq.heappop(que) if cost[v] != d: continue for u in e[v]: if dist[u] == 0: continue if dist[u] <= s: c = q else: c = p if cost[u] > d + c: cost[u] = d + c heapq.heappush(que, [d + c, u]) if dist[n - 1] <= s: print(cost[n - 1] - q) else: print(cost[n - 1] - p)
Submission Info
Submission Time | |
---|---|
Task | E - ゾンビ島 (Zombie Island) |
User | Pro_ktmr |
Language | PyPy3 (7.3.0) |
Score | 100 |
Code Size | 1159 Byte |
Status | AC |
Exec Time | 470 ms |
Memory | 93036 KB |
Judge Result
Set Name | set01 | set02 | set03 | set04 | set05 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 20 / 20 | 20 / 20 | 20 / 20 | 20 / 20 | 20 / 20 | ||||||||||
Status |
|
|
|
|
|
Set Name | Test Cases |
---|---|
set01 | data1 |
set02 | data2 |
set03 | data3 |
set04 | data4 |
set05 | data5 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
data1 | AC | 74 ms | 65712 KB |
data2 | AC | 279 ms | 88840 KB |
data3 | AC | 137 ms | 75796 KB |
data4 | AC | 470 ms | 93036 KB |
data5 | AC | 470 ms | 90072 KB |