Submission #70442534


Source Code Expand

n, m = map(int, input().split())
G = [set() for _ in range(n)]
for _ in range(m):
  u, v = map(lambda x:int(x)-1, input().split())
  G[u].add(v)
  G[v].add(u)

S = list(input())
S = [s=='S' for s in S]

import heapq
que = []
C1 = [[-1, 1<<60] for _ in range(n)]
C2 = [[-1, 1<<60] for _ in range(n)]

for i in range(n):
  if S[i]:
    heapq.heappush(que, (0, i, i))
    C1[i] = (i, 0)

# print(que)
while que:
  cost, v, fr = heapq.heappop(que)
  if fr not in (C1[v][0], C2[v][0]) or cost not in (C1[v][1], C2[v][1]): 
    continue
  for v_ in G[v]:
    if C2[v_][1]>cost+1 and C1[v_][0]!=fr:
      C2[v_][0] = fr
      C2[v_][1] = cost+1
      if C1[v_][1]>C2[v_][1]:
        C1[v_], C2[v_] = C2[v_], C1[v_]
      heapq.heappush(que, (cost+1, v_, fr))

for i in range(n):
  if not S[i]:
    print(C1[i][1]+C2[i][1])

Submission Info

Submission Time
Task E - Hit and Away
User uparupaaa
Language Python (PyPy 3.10-v7.3.12)
Score 450
Code Size 850 Byte
Status AC
Exec Time 1889 ms
Memory 248348 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 2
AC × 54
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt
Case Name Status Exec Time Memory
example_00.txt AC 59 ms 76432 KiB
example_01.txt AC 58 ms 76520 KiB
hand_00.txt AC 774 ms 176596 KiB
hand_01.txt AC 1111 ms 201268 KiB
hand_02.txt AC 1668 ms 226752 KiB
hand_03.txt AC 1742 ms 246240 KiB
hand_04.txt AC 1889 ms 242100 KiB
hand_05.txt AC 194 ms 111424 KiB
hand_06.txt AC 193 ms 111316 KiB
hand_07.txt AC 657 ms 175964 KiB
hand_08.txt AC 953 ms 170676 KiB
hand_09.txt AC 199 ms 110880 KiB
hand_10.txt AC 575 ms 176552 KiB
hand_11.txt AC 810 ms 199552 KiB
hand_12.txt AC 816 ms 199448 KiB
hand_13.txt AC 1146 ms 222756 KiB
hand_14.txt AC 1807 ms 248348 KiB
hand_15.txt AC 1791 ms 246172 KiB
random_00.txt AC 1666 ms 217024 KiB
random_01.txt AC 1598 ms 217492 KiB
random_02.txt AC 1596 ms 216460 KiB
random_03.txt AC 1662 ms 216620 KiB
random_04.txt AC 1666 ms 216504 KiB
random_05.txt AC 1639 ms 217868 KiB
random_06.txt AC 774 ms 177248 KiB
random_07.txt AC 765 ms 179892 KiB
random_08.txt AC 843 ms 184584 KiB
random_09.txt AC 855 ms 176308 KiB
random_10.txt AC 882 ms 179860 KiB
random_11.txt AC 1040 ms 187976 KiB
random_12.txt AC 739 ms 177212 KiB
random_13.txt AC 758 ms 179748 KiB
random_14.txt AC 846 ms 184116 KiB
random_15.txt AC 865 ms 177264 KiB
random_16.txt AC 909 ms 179984 KiB
random_17.txt AC 928 ms 180952 KiB
random_18.txt AC 144 ms 93020 KiB
random_19.txt AC 163 ms 98472 KiB
random_20.txt AC 194 ms 105912 KiB
random_21.txt AC 187 ms 105808 KiB
random_22.txt AC 171 ms 99520 KiB
random_23.txt AC 150 ms 93348 KiB
random_24.txt AC 353 ms 111892 KiB
random_25.txt AC 322 ms 109916 KiB
random_26.txt AC 354 ms 112072 KiB
random_27.txt AC 316 ms 111016 KiB
random_28.txt AC 392 ms 113452 KiB
random_29.txt AC 340 ms 111628 KiB
random_30.txt AC 1720 ms 209952 KiB
random_31.txt AC 1005 ms 165412 KiB
random_32.txt AC 1288 ms 174140 KiB
random_33.txt AC 1717 ms 221168 KiB
random_34.txt AC 1104 ms 160072 KiB
random_35.txt AC 1216 ms 167672 KiB