結果

問題 No.1382 Travel in Mitaru city
ユーザー mkawa2mkawa2
提出日時 2021-02-07 22:49:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,820 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 10,960 KB
実行使用メモリ 40,392 KB
最終ジャッジ日時 2023-09-17 23:34:58
合計ジャッジ時間 27,352 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,224 KB
testcase_01 AC 16 ms
8,196 KB
testcase_02 AC 17 ms
8,092 KB
testcase_03 AC 17 ms
8,088 KB
testcase_04 AC 17 ms
8,212 KB
testcase_05 AC 17 ms
8,140 KB
testcase_06 WA -
testcase_07 AC 196 ms
16,008 KB
testcase_08 WA -
testcase_09 AC 276 ms
18,920 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 539 ms
40,020 KB
testcase_28 AC 523 ms
40,128 KB
testcase_29 AC 516 ms
39,952 KB
testcase_30 AC 478 ms
39,940 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 281 ms
35,160 KB
testcase_37 AC 58 ms
12,564 KB
testcase_38 AC 307 ms
38,076 KB
testcase_39 AC 89 ms
16,040 KB
testcase_40 AC 244 ms
30,812 KB
testcase_41 AC 297 ms
33,336 KB
testcase_42 AC 351 ms
38,728 KB
testcase_43 AC 303 ms
34,432 KB
testcase_44 AC 131 ms
18,812 KB
testcase_45 AC 273 ms
32,208 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 331 ms
28,800 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 AC 27 ms
8,536 KB
testcase_62 AC 17 ms
8,084 KB
testcase_63 AC 76 ms
9,184 KB
testcase_64 AC 33 ms
8,596 KB
testcase_65 AC 18 ms
8,012 KB
testcase_66 AC 26 ms
8,584 KB
testcase_67 AC 28 ms
8,576 KB
testcase_68 AC 38 ms
8,596 KB
testcase_69 AC 25 ms
8,500 KB
testcase_70 AC 45 ms
8,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def MI(): return map(int, sys.stdin.buffer.readline().split())
def MI1(): return map(int1, sys.stdin.buffer.readline().split())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [[(-1, 0), (1, 0)], [(0, -1), (0, 1)]]
inf = 10**16
md = 998244353
# md = 10**9+7

class UnionFind:
    def __init__(self, n):
        self.state = [-1] * n
        # self.size_table = [1] * n
        # cntはグループ数
        # self.cnt = n

    def root(self, u):
        v = self.state[u]
        if v < 0: return u
        self.state[u] = res = self.root(v)
        return res

    def merge(self, u, v):
        ru = self.root(u)
        rv = self.root(v)
        if ru == rv: return
        du = self.state[ru]
        dv = self.state[rv]
        if du > dv: ru, rv = rv, ru
        if du == dv: self.state[ru] -= 1
        self.state[rv] = ru
        # self.cnt -= 1
        # self.size_table[ru] += self.size_table[rv]
        return

n,m,s,t=MI()
s,t=s-1,t-1
pp=LI()
to=[[] for _ in range(n)]
for _ in range(m):
    u,v=MI1()
    to[u].append(v)
    to[v].append(u)

pu=[(p,u) for u,p in enumerate(pp)]
pu.sort(reverse=True)

pre=pp[s]
uf=UnionFind(n)
fin=[False]*n
ans=0
for p,u in pu:
    fin[u]=True
    for v in to[u]:
        if fin[v]:continue
        uf.merge(u,v)
    if p<pre and uf.root(s)==uf.root(u):
        ans+=1
        pre=p

print(ans)
0