結果
問題 |
No.1382 Travel in Mitaru city
|
ユーザー |
![]() |
提出日時 | 2023-03-02 12:35:12 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,221 bytes |
コンパイル時間 | 157 ms |
コンパイル使用メモリ | 82,568 KB |
実行使用メモリ | 92,752 KB |
最終ジャッジ日時 | 2024-09-17 08:19:22 |
合計ジャッジ時間 | 12,424 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 WA * 38 |
ソースコード
import sys readline = sys.stdin.readline class UnionFind(object): def __init__(self, n=1): self.par = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x self.size[x] += self.size[y] def is_same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): x = self.find(x) return self.size[x] N, M, S, T = map(int, readline().split()) S, T = S - 1, T - 1 P = list(map(int, readline().split())) U = UnionFind(N) for i in range(M): A, B = map(int, readline().split()) A, B = A - 1, B - 1 U.union(A, B) SS = set() for i in range(N): if U.find(i) != U.find(S): continue if P[i] < P[S]: SS.add(P[i]) print(len(SS))