結果

問題 No.1382 Travel in Mitaru city
ユーザー marroncastlemarroncastle
提出日時 2021-02-07 22:59:46
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 1,590 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 103,836 KB
最終ジャッジ日時 2023-09-18 00:22:31
合計ジャッジ時間 20,470 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,668 KB
testcase_01 AC 95 ms
71,388 KB
testcase_02 AC 92 ms
71,636 KB
testcase_03 AC 96 ms
71,632 KB
testcase_04 AC 93 ms
71,520 KB
testcase_05 AC 92 ms
71,632 KB
testcase_06 AC 237 ms
84,212 KB
testcase_07 AC 229 ms
82,976 KB
testcase_08 AC 209 ms
81,564 KB
testcase_09 AC 243 ms
84,308 KB
testcase_10 AC 232 ms
84,564 KB
testcase_11 WA -
testcase_12 AC 346 ms
92,520 KB
testcase_13 AC 355 ms
92,420 KB
testcase_14 AC 321 ms
92,812 KB
testcase_15 AC 340 ms
92,464 KB
testcase_16 AC 442 ms
101,604 KB
testcase_17 AC 428 ms
101,524 KB
testcase_18 AC 421 ms
101,700 KB
testcase_19 AC 445 ms
101,600 KB
testcase_20 AC 410 ms
101,724 KB
testcase_21 AC 432 ms
101,772 KB
testcase_22 AC 411 ms
101,516 KB
testcase_23 AC 429 ms
101,712 KB
testcase_24 AC 414 ms
101,816 KB
testcase_25 AC 421 ms
101,724 KB
testcase_26 AC 363 ms
101,544 KB
testcase_27 AC 381 ms
101,552 KB
testcase_28 AC 395 ms
101,764 KB
testcase_29 AC 387 ms
101,752 KB
testcase_30 AC 375 ms
101,624 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 186 ms
98,300 KB
testcase_37 AC 126 ms
80,904 KB
testcase_38 AC 196 ms
100,692 KB
testcase_39 AC 136 ms
84,216 KB
testcase_40 AC 175 ms
93,968 KB
testcase_41 AC 175 ms
96,352 KB
testcase_42 AC 195 ms
101,096 KB
testcase_43 AC 183 ms
97,976 KB
testcase_44 AC 151 ms
86,276 KB
testcase_45 AC 180 ms
95,756 KB
testcase_46 AC 211 ms
85,684 KB
testcase_47 AC 369 ms
103,000 KB
testcase_48 AC 295 ms
96,668 KB
testcase_49 AC 375 ms
103,836 KB
testcase_50 AC 254 ms
90,160 KB
testcase_51 AC 234 ms
97,924 KB
testcase_52 AC 258 ms
100,812 KB
testcase_53 AC 153 ms
84,296 KB
testcase_54 AC 183 ms
89,400 KB
testcase_55 AC 254 ms
100,764 KB
testcase_56 AC 161 ms
85,820 KB
testcase_57 AC 202 ms
93,344 KB
testcase_58 AC 135 ms
80,528 KB
testcase_59 AC 168 ms
85,968 KB
testcase_60 AC 248 ms
100,316 KB
testcase_61 AC 105 ms
77,340 KB
testcase_62 AC 92 ms
71,588 KB
testcase_63 AC 118 ms
78,556 KB
testcase_64 AC 105 ms
77,248 KB
testcase_65 AC 98 ms
76,192 KB
testcase_66 AC 104 ms
77,024 KB
testcase_67 AC 103 ms
77,136 KB
testcase_68 AC 106 ms
77,184 KB
testcase_69 AC 105 ms
77,488 KB
testcase_70 AC 107 ms
77,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from heapq import *
from collections import defaultdict
class Graph:
  def __init__(self, N, M=-1):
    self.V = N
    if M>=0: self.E = M
    self.edge = [[] for _ in range(self.V)]
    self.edge_rev = [[] for _ in range(self.V)]
    self.order = []
    self.to = [0]*self.V
    self.visited = [False]*self.V
    self.dp = [0]*self.V

  def add_edges(self, ind=1, bi=False, rev=False):
    for i in range(self.E):
      a,b = map(int, input().split())
      a -= ind; b -= ind
      self.edge[a].append(b)
      if rev: self.edge_rev[b].append(a)
      if not bi: self.to[b] += 1
      if bi: self.edge[b].append(a)

  def add_edge(self, a, b, dist=-1, bi=False, rev=False):
    if dist>=0:
      self.edge[a].append((dist, b))
      if rev: self.edge_rev[b].append((dist, a))
      if bi: self.edge[b].append((dist, a))
    else:
      self.edge[a].append(b)
      if rev: self.edge_rev[b].append(a)
      if bi: self.edge[b].append(a)
    if not bi: self.to[b] += 1

  def bfs(self, start):
    self.visited[start] = True
    d = [(-P[start], start)]
    heapify(d)
    dic = defaultdict(lambda: False)
    ans = 0
    while len(d)>0:
      p,v = heappop(d)
      for w in self.edge[v]:
        if not self.visited[w]:
          if P[w]<-p and dic[P[w]]==False:
            ans += 1
            dic[P[w]] = True
          else: P[w] = -p
          self.visited[w] = True
          heappush(d, (-P[w],w))
    return ans

N, M, S, T = map(int, input().split())
P = list(map(int, input().split()))
G = Graph(N,M)
G.add_edges(bi=True)
print(G.bfs(S-1))
0