結果
問題 |
No.1382 Travel in Mitaru city
|
ユーザー |
|
提出日時 | 2021-02-07 22:07:11 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,285 bytes |
コンパイル時間 | 146 ms |
コンパイル使用メモリ | 82,408 KB |
実行使用メモリ | 97,224 KB |
最終ジャッジ日時 | 2024-07-04 15:40:49 |
合計ジャッジ時間 | 13,257 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 WA * 38 |
ソースコード
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * 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 if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def same(self, x, y): return self.find(x) == self.find(y) def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def size(self,x): return abs(self.parents[self.find(x)]) def groups(self): roots = self.roots() r_to_g = {} for i, r in enumerate(roots): r_to_g[r] = i groups = [[] for _ in roots] for i in range(self.n): groups[r_to_g[self.find(i)]].append(i) return groups N, M, S, T = map(int, input().split()) P = list(map(int, input().split())) uf = UnionFind(N) for i in range(M): a,b = map(int, input().split()) uf.union(a-1,b-1) lis = uf.members(S-1) s = set() for l in lis: if P[l]<P[S-1]: s.add(P[l]) print(len(list(s)))