結果

問題 No.1382 Travel in Mitaru city
ユーザー 👑 KazunKazun
提出日時 2021-02-07 21:43:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 561 ms / 2,000 ms
コード長 2,712 bytes
コンパイル時間 410 ms
コンパイル使用メモリ 87,212 KB
実行使用メモリ 104,120 KB
最終ジャッジ日時 2023-09-17 21:05:43
合計ジャッジ時間 25,565 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,364 KB
testcase_01 AC 91 ms
71,532 KB
testcase_02 AC 89 ms
71,668 KB
testcase_03 AC 91 ms
71,644 KB
testcase_04 AC 89 ms
71,520 KB
testcase_05 AC 91 ms
71,684 KB
testcase_06 AC 238 ms
83,576 KB
testcase_07 AC 217 ms
82,900 KB
testcase_08 AC 192 ms
80,984 KB
testcase_09 AC 233 ms
84,048 KB
testcase_10 AC 225 ms
83,740 KB
testcase_11 AC 409 ms
94,096 KB
testcase_12 AC 371 ms
92,240 KB
testcase_13 AC 414 ms
93,108 KB
testcase_14 AC 399 ms
91,592 KB
testcase_15 AC 391 ms
91,508 KB
testcase_16 AC 530 ms
99,476 KB
testcase_17 AC 553 ms
99,612 KB
testcase_18 AC 561 ms
102,188 KB
testcase_19 AC 535 ms
104,120 KB
testcase_20 AC 529 ms
100,956 KB
testcase_21 AC 501 ms
99,428 KB
testcase_22 AC 482 ms
99,584 KB
testcase_23 AC 524 ms
99,520 KB
testcase_24 AC 528 ms
99,632 KB
testcase_25 AC 539 ms
99,416 KB
testcase_26 AC 498 ms
103,756 KB
testcase_27 AC 472 ms
101,444 KB
testcase_28 AC 481 ms
102,308 KB
testcase_29 AC 500 ms
101,108 KB
testcase_30 AC 373 ms
98,292 KB
testcase_31 AC 420 ms
96,380 KB
testcase_32 AC 478 ms
102,076 KB
testcase_33 AC 446 ms
98,384 KB
testcase_34 AC 383 ms
92,748 KB
testcase_35 AC 303 ms
88,612 KB
testcase_36 AC 242 ms
95,148 KB
testcase_37 AC 144 ms
80,688 KB
testcase_38 AC 253 ms
97,072 KB
testcase_39 AC 166 ms
83,744 KB
testcase_40 AC 212 ms
91,652 KB
testcase_41 AC 227 ms
93,344 KB
testcase_42 AC 249 ms
97,456 KB
testcase_43 AC 228 ms
95,092 KB
testcase_44 AC 169 ms
85,264 KB
testcase_45 AC 215 ms
93,404 KB
testcase_46 AC 178 ms
84,556 KB
testcase_47 AC 328 ms
99,880 KB
testcase_48 AC 270 ms
92,740 KB
testcase_49 AC 340 ms
101,232 KB
testcase_50 AC 233 ms
90,904 KB
testcase_51 AC 445 ms
96,260 KB
testcase_52 AC 501 ms
101,088 KB
testcase_53 AC 236 ms
84,684 KB
testcase_54 AC 299 ms
88,864 KB
testcase_55 AC 492 ms
98,380 KB
testcase_56 AC 283 ms
87,024 KB
testcase_57 AC 384 ms
93,968 KB
testcase_58 AC 207 ms
81,808 KB
testcase_59 AC 276 ms
86,084 KB
testcase_60 AC 430 ms
97,920 KB
testcase_61 AC 117 ms
77,672 KB
testcase_62 AC 91 ms
71,704 KB
testcase_63 AC 133 ms
78,656 KB
testcase_64 AC 116 ms
78,104 KB
testcase_65 AC 104 ms
76,984 KB
testcase_66 AC 115 ms
77,776 KB
testcase_67 AC 115 ms
78,020 KB
testcase_68 AC 114 ms
77,996 KB
testcase_69 AC 113 ms
77,432 KB
testcase_70 AC 121 ms
78,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Union_Find():
    def __init__(self,N):
        """0,1,...,n-1を要素として初期化する.

        N:要素数
        """
        self.n=N
        self.parents=[-1]*N
        self.rank=[0]*N

    def find(self, x):
        """要素xの属している族を調べる.

        x:要素
        """
        V=[]
        while self.parents[x]>=0:
            V.append(x)
            x=self.parents[x]

        for v in V:
            self.parents[v]=x
        return x

    def union(self, x, y):
        """要素x,yを同一視する.

        x,y:要素
        """
        x=self.find(x)
        y=self.find(y)

        if x==y:
            return

        if self.rank[x]<self.rank[y]:
            x,y=y,x

        self.parents[x]+=self.parents[y]
        self.parents[y]=x

        if self.rank[x]==self.rank[y]:
            self.rank[x]+=1

    def size(self, x):
        """要素xの属している要素の数.

        x:要素
        """
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """要素x,yは同一視されているか?

        x,y:要素
        """
        return self.find(x) == self.find(y)

    def members(self, x):
        """要素xが属している族の要素.
        ※族の要素の個数が欲しいときはsizeを使うこと!!

        x:要素
        """
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        """族の名前のリスト
        """
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        """族の個数
        """
        return len(self.roots())

    def all_group_members(self):
        """全ての族の出力
        """
        X={r:[] for r in self.roots()}
        for k in range(self.n):
            X[self.find(k)].append(k)
        return X

    def refresh(self):
        for i in range(self.n):
            _=self.find(i)

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

    def __repr__(self):
        return self.__str__()
#================================================
from collections import defaultdict
import sys

input=sys.stdin.readline
N,M,S,T=map(int,input().split())
P=["*"]+list(map(int,input().split()))

E=[[] for _ in range(N+1)]
for _ in range(M):
    a,b=map(int,input().split())
    E[a].append(b)
    E[b].append(a)

U=Union_Find(N+1)
F=sorted(range(1,N+1),key=lambda x:P[x],reverse=True)
Flag=defaultdict(int)
Ans=0

for x in F:
    for y in E[x]:
        if P[y]>=P[x]:
            U.union(x,y)

    if P[x]<P[S] and U.same(x,S) and Flag[P[x]]==0:
        Ans+=1
        Flag[P[x]]=1
print(Ans)
0