結果
問題 | No.1805 Approaching Many Typhoon |
ユーザー | mkawa2 |
提出日時 | 2024-09-11 14:59:01 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 53 ms / 2,000 ms |
コード長 | 1,702 bytes |
コンパイル時間 | 394 ms |
コンパイル使用メモリ | 82,224 KB |
実行使用メモリ | 66,092 KB |
最終ジャッジ日時 | 2024-09-11 14:59:05 |
合計ジャッジ時間 | 3,139 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,324 KB |
testcase_01 | AC | 37 ms
52,884 KB |
testcase_02 | AC | 39 ms
53,292 KB |
testcase_03 | AC | 38 ms
52,988 KB |
testcase_04 | AC | 38 ms
52,708 KB |
testcase_05 | AC | 37 ms
53,020 KB |
testcase_06 | AC | 39 ms
53,700 KB |
testcase_07 | AC | 37 ms
53,500 KB |
testcase_08 | AC | 38 ms
53,636 KB |
testcase_09 | AC | 38 ms
52,524 KB |
testcase_10 | AC | 37 ms
53,788 KB |
testcase_11 | AC | 38 ms
54,248 KB |
testcase_12 | AC | 37 ms
52,464 KB |
testcase_13 | AC | 38 ms
54,236 KB |
testcase_14 | AC | 37 ms
52,744 KB |
testcase_15 | AC | 39 ms
52,900 KB |
testcase_16 | AC | 38 ms
53,388 KB |
testcase_17 | AC | 38 ms
53,976 KB |
testcase_18 | AC | 38 ms
52,876 KB |
testcase_19 | AC | 37 ms
53,696 KB |
testcase_20 | AC | 38 ms
52,904 KB |
testcase_21 | AC | 38 ms
54,004 KB |
testcase_22 | AC | 38 ms
53,984 KB |
testcase_23 | AC | 37 ms
52,532 KB |
testcase_24 | AC | 37 ms
53,404 KB |
testcase_25 | AC | 38 ms
53,504 KB |
testcase_26 | AC | 38 ms
53,672 KB |
testcase_27 | AC | 37 ms
53,352 KB |
testcase_28 | AC | 52 ms
65,320 KB |
testcase_29 | AC | 52 ms
66,092 KB |
testcase_30 | AC | 52 ms
65,660 KB |
testcase_31 | AC | 53 ms
65,864 KB |
testcase_32 | AC | 39 ms
53,584 KB |
testcase_33 | AC | 39 ms
53,484 KB |
testcase_34 | AC | 39 ms
55,124 KB |
testcase_35 | AC | 46 ms
60,620 KB |
testcase_36 | AC | 46 ms
62,112 KB |
testcase_37 | AC | 38 ms
52,940 KB |
testcase_38 | AC | 37 ms
53,632 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) # sys.set_int_max_str_digits(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = -1-(-1 << 31) inf = -1-(-1 << 62) # md = 10**9+7 md = 998244353 class UnionFind: def __init__(self, n): self._tree = [-1]*n # number of connected component self.cnt = n def root(self, u): stack = [] while self._tree[u] >= 0: stack.append(u) u = self._tree[u] for v in stack: self._tree[v] = u return u def same(self, u, v): return self.root(u) == self.root(v) def merge(self, u, v): u, v = self.root(u), self.root(v) if u == v: return False if self._tree[u] > self._tree[v]: u, v = v, u self._tree[u] += self._tree[v] self._tree[v] = u self.cnt -= 1 return True # size of connected component def size(self, u): return -self._tree[self.root(u)] n,m=LI() s,g=LI1() uv=LLI1(m) II() ng=set(LI1()) uf=UnionFind(n) for u,v in uv: if u in ng or v in ng:continue uf.merge(u,v) print("Yes" if uf.same(s,g) else "No")