結果

問題 No.1382 Travel in Mitaru city
ユーザー 👑 KazunKazun
提出日時 2021-02-07 21:43:01
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,711 bytes
コンパイル時間 1,498 ms
コンパイル使用メモリ 86,980 KB
実行使用メモリ 104,332 KB
最終ジャッジ日時 2023-09-17 21:04:04
合計ジャッジ時間 25,366 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,648 KB
testcase_01 AC 96 ms
71,664 KB
testcase_02 AC 94 ms
71,848 KB
testcase_03 AC 92 ms
71,392 KB
testcase_04 AC 96 ms
71,824 KB
testcase_05 AC 96 ms
71,840 KB
testcase_06 AC 252 ms
83,384 KB
testcase_07 AC 223 ms
82,936 KB
testcase_08 AC 195 ms
81,144 KB
testcase_09 AC 247 ms
83,756 KB
testcase_10 AC 235 ms
83,696 KB
testcase_11 AC 436 ms
94,040 KB
testcase_12 AC 389 ms
92,200 KB
testcase_13 AC 446 ms
93,292 KB
testcase_14 AC 427 ms
91,764 KB
testcase_15 AC 411 ms
91,760 KB
testcase_16 AC 560 ms
99,568 KB
testcase_17 AC 581 ms
99,484 KB
testcase_18 AC 600 ms
102,268 KB
testcase_19 AC 582 ms
104,120 KB
testcase_20 AC 577 ms
101,016 KB
testcase_21 AC 527 ms
99,732 KB
testcase_22 AC 516 ms
99,768 KB
testcase_23 AC 561 ms
99,560 KB
testcase_24 AC 562 ms
99,592 KB
testcase_25 AC 574 ms
99,748 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 453 ms
103,864 KB
testcase_30 AC 264 ms
98,732 KB
testcase_31 AC 439 ms
96,496 KB
testcase_32 AC 497 ms
102,132 KB
testcase_33 WA -
testcase_34 AC 402 ms
92,828 KB
testcase_35 AC 323 ms
89,092 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 175 ms
84,768 KB
testcase_47 AC 302 ms
100,092 KB
testcase_48 AC 257 ms
93,372 KB
testcase_49 AC 326 ms
101,664 KB
testcase_50 AC 220 ms
89,928 KB
testcase_51 AC 467 ms
96,116 KB
testcase_52 AC 535 ms
101,404 KB
testcase_53 AC 259 ms
85,136 KB
testcase_54 AC 318 ms
88,760 KB
testcase_55 AC 530 ms
98,608 KB
testcase_56 AC 293 ms
86,936 KB
testcase_57 AC 400 ms
94,408 KB
testcase_58 AC 215 ms
81,956 KB
testcase_59 AC 294 ms
86,060 KB
testcase_60 AC 459 ms
98,420 KB
testcase_61 AC 114 ms
77,480 KB
testcase_62 AC 89 ms
71,812 KB
testcase_63 AC 131 ms
78,844 KB
testcase_64 AC 118 ms
78,164 KB
testcase_65 AC 102 ms
77,076 KB
testcase_66 AC 113 ms
77,988 KB
testcase_67 AC 115 ms
77,964 KB
testcase_68 AC 119 ms
78,052 KB
testcase_69 AC 114 ms
77,588 KB
testcase_70 AC 122 ms
78,264 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