結果

問題 No.1382 Travel in Mitaru city
ユーザー 👑 rin204rin204
提出日時 2022-04-16 16:14:12
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,957 bytes
コンパイル時間 343 ms
コンパイル使用メモリ 87,208 KB
実行使用メモリ 113,508 KB
最終ジャッジ日時 2023-08-26 19:05:30
合計ジャッジ時間 26,220 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,140 KB
testcase_01 AC 71 ms
70,952 KB
testcase_02 AC 71 ms
71,312 KB
testcase_03 AC 70 ms
71,164 KB
testcase_04 AC 71 ms
71,136 KB
testcase_05 AC 72 ms
71,284 KB
testcase_06 AC 229 ms
82,816 KB
testcase_07 AC 220 ms
81,652 KB
testcase_08 AC 213 ms
81,540 KB
testcase_09 AC 228 ms
82,792 KB
testcase_10 AC 217 ms
82,548 KB
testcase_11 AC 419 ms
99,544 KB
testcase_12 AC 458 ms
99,660 KB
testcase_13 AC 448 ms
98,348 KB
testcase_14 AC 487 ms
99,440 KB
testcase_15 AC 466 ms
99,332 KB
testcase_16 AC 581 ms
112,472 KB
testcase_17 AC 607 ms
112,472 KB
testcase_18 AC 598 ms
112,720 KB
testcase_19 AC 598 ms
112,496 KB
testcase_20 AC 568 ms
112,748 KB
testcase_21 AC 587 ms
112,632 KB
testcase_22 AC 580 ms
112,516 KB
testcase_23 AC 604 ms
112,500 KB
testcase_24 AC 543 ms
112,372 KB
testcase_25 AC 604 ms
112,628 KB
testcase_26 WA -
testcase_27 AC 521 ms
94,824 KB
testcase_28 WA -
testcase_29 AC 540 ms
94,892 KB
testcase_30 AC 428 ms
95,000 KB
testcase_31 AC 420 ms
91,920 KB
testcase_32 AC 424 ms
94,868 KB
testcase_33 AC 364 ms
94,524 KB
testcase_34 AC 359 ms
87,516 KB
testcase_35 AC 298 ms
85,484 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 159 ms
82,068 KB
testcase_47 AC 224 ms
92,128 KB
testcase_48 AC 219 ms
87,516 KB
testcase_49 AC 231 ms
94,720 KB
testcase_50 AC 180 ms
84,288 KB
testcase_51 AC 470 ms
108,440 KB
testcase_52 AC 520 ms
113,508 KB
testcase_53 AC 265 ms
86,776 KB
testcase_54 AC 362 ms
95,220 KB
testcase_55 AC 534 ms
112,364 KB
testcase_56 AC 315 ms
90,152 KB
testcase_57 AC 442 ms
102,180 KB
testcase_58 AC 254 ms
82,728 KB
testcase_59 AC 315 ms
89,680 KB
testcase_60 AC 510 ms
111,884 KB
testcase_61 WA -
testcase_62 AC 71 ms
71,208 KB
testcase_63 AC 136 ms
78,056 KB
testcase_64 AC 120 ms
78,052 KB
testcase_65 AC 90 ms
75,716 KB
testcase_66 WA -
testcase_67 AC 119 ms
78,164 KB
testcase_68 WA -
testcase_69 AC 120 ms
78,472 KB
testcase_70 AC 125 ms
78,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        self.group = n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return
        self.group -= 1
        if self.parents[x] > self.parents[y]:
            x, y = y, x

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

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, 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 self.group

    def all_group_members(self):
        dic = {r:[] for r in self.roots()}
        for i in range(self.n):
            dic[self.find(i)].append(i)
        return dic

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

n, m, s, t = map(int, input().split())
P = list(map(int, input().split()))
s -= 1
t -= 1
edges = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if P[a] > P[b]:
        a, b = b, a
    edges[a].append(b)
    
dic = {}
for i, p in enumerate(P):
    if p not in dic:
        dic[p] = []
    dic[p].append(i)
    
ans = 0
UF = UnionFind(n)
for p in sorted(dic.keys(), reverse = True):
    flg = False
    tmp = []
    for u in dic[p]:
        for v in edges[u]:
            if UF.same(v, s):
                flg = True

    if flg:
        ans += 1
    for u in dic[p]:
        for v in edges[u]:
            UF.union(u, v)
    
print(ans)



0