結果

問題 No.1382 Travel in Mitaru city
ユーザー 👑 KazunKazun
提出日時 2021-02-07 21:36:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,629 bytes
コンパイル時間 395 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 107,128 KB
最終ジャッジ日時 2023-09-17 20:53:33
合計ジャッジ時間 26,580 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
71,188 KB
testcase_01 AC 96 ms
71,320 KB
testcase_02 AC 93 ms
71,516 KB
testcase_03 AC 93 ms
71,600 KB
testcase_04 AC 94 ms
71,576 KB
testcase_05 AC 94 ms
71,404 KB
testcase_06 WA -
testcase_07 AC 250 ms
81,784 KB
testcase_08 AC 212 ms
80,808 KB
testcase_09 AC 267 ms
82,368 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 AC 502 ms
101,564 KB
testcase_27 AC 455 ms
100,000 KB
testcase_28 AC 458 ms
102,084 KB
testcase_29 AC 455 ms
101,060 KB
testcase_30 AC 375 ms
98,440 KB
testcase_31 WA -
testcase_32 AC 490 ms
102,560 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 343 ms
89,492 KB
testcase_36 AC 259 ms
95,304 KB
testcase_37 AC 158 ms
80,776 KB
testcase_38 AC 276 ms
100,452 KB
testcase_39 AC 182 ms
84,112 KB
testcase_40 AC 222 ms
91,704 KB
testcase_41 AC 230 ms
93,728 KB
testcase_42 AC 260 ms
98,640 KB
testcase_43 AC 233 ms
95,416 KB
testcase_44 AC 180 ms
84,756 KB
testcase_45 AC 226 ms
93,476 KB
testcase_46 WA -
testcase_47 AC 342 ms
97,352 KB
testcase_48 AC 301 ms
90,864 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 135 ms
78,016 KB
testcase_62 AC 92 ms
71,684 KB
testcase_63 AC 152 ms
78,348 KB
testcase_64 AC 136 ms
78,176 KB
testcase_65 AC 118 ms
76,716 KB
testcase_66 AC 136 ms
78,180 KB
testcase_67 AC 137 ms
78,112 KB
testcase_68 AC 141 ms
78,236 KB
testcase_69 AC 135 ms
78,584 KB
testcase_70 AC 143 ms
78,836 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
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)

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]:
        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