結果
問題 | No.1805 Approaching Many Typhoon |
ユーザー | Shirotsume |
提出日時 | 2022-01-12 20:26:58 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 54 ms / 2,000 ms |
コード長 | 2,071 bytes |
コンパイル時間 | 231 ms |
コンパイル使用メモリ | 82,140 KB |
実行使用メモリ | 66,152 KB |
最終ジャッジ日時 | 2024-11-15 15:04:25 |
合計ジャッジ時間 | 2,942 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
53,896 KB |
testcase_01 | AC | 41 ms
53,496 KB |
testcase_02 | AC | 39 ms
53,084 KB |
testcase_03 | AC | 39 ms
52,868 KB |
testcase_04 | AC | 39 ms
53,288 KB |
testcase_05 | AC | 40 ms
53,740 KB |
testcase_06 | AC | 39 ms
52,820 KB |
testcase_07 | AC | 39 ms
53,912 KB |
testcase_08 | AC | 39 ms
53,388 KB |
testcase_09 | AC | 39 ms
53,016 KB |
testcase_10 | AC | 39 ms
53,012 KB |
testcase_11 | AC | 39 ms
53,264 KB |
testcase_12 | AC | 39 ms
53,212 KB |
testcase_13 | AC | 44 ms
52,516 KB |
testcase_14 | AC | 41 ms
54,040 KB |
testcase_15 | AC | 40 ms
54,468 KB |
testcase_16 | AC | 40 ms
54,400 KB |
testcase_17 | AC | 39 ms
53,012 KB |
testcase_18 | AC | 40 ms
53,780 KB |
testcase_19 | AC | 40 ms
53,052 KB |
testcase_20 | AC | 39 ms
53,160 KB |
testcase_21 | AC | 39 ms
53,292 KB |
testcase_22 | AC | 40 ms
53,812 KB |
testcase_23 | AC | 39 ms
53,280 KB |
testcase_24 | AC | 39 ms
53,240 KB |
testcase_25 | AC | 39 ms
53,304 KB |
testcase_26 | AC | 38 ms
52,808 KB |
testcase_27 | AC | 39 ms
52,832 KB |
testcase_28 | AC | 54 ms
65,504 KB |
testcase_29 | AC | 54 ms
66,000 KB |
testcase_30 | AC | 54 ms
64,720 KB |
testcase_31 | AC | 54 ms
66,152 KB |
testcase_32 | AC | 39 ms
52,864 KB |
testcase_33 | AC | 40 ms
53,312 KB |
testcase_34 | AC | 41 ms
54,452 KB |
testcase_35 | AC | 46 ms
60,820 KB |
testcase_36 | AC | 48 ms
60,916 KB |
testcase_37 | AC | 39 ms
52,868 KB |
testcase_38 | AC | 39 ms
53,324 KB |
ソースコード
class dsu(): n=1 parent_or_size=[-1 for i in range(n)] def __init__(self,N): self.n=N self.parent_or_size=[-1 for i in range(N)] def merge(self,a,b): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) assert 0<=b<self.n, "0<=b<n,b={0},n={1}".format(b,self.n) x=self.leader(a) y=self.leader(b) if x==y: return x if (-self.parent_or_size[x]<-self.parent_or_size[y]): x,y=y,x self.parent_or_size[x]+=self.parent_or_size[y] self.parent_or_size[y]=x return x def same(self,a,b): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) assert 0<=b<self.n, "0<=b<n,b={0},n={1}".format(b,self.n) return self.leader(a)==self.leader(b) def leader(self,a): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) if (self.parent_or_size[a]<0): return a self.parent_or_size[a]=self.leader(self.parent_or_size[a]) return self.parent_or_size[a] def size(self,a): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) return -self.parent_or_size[self.leader(a)] def groups(self): leader_buf=[0 for i in range(self.n)] group_size=[0 for i in range(self.n)] for i in range(self.n): leader_buf[i]=self.leader(i) group_size[leader_buf[i]]+=1 result=[[] for i in range(self.n)] for i in range(self.n): result[leader_buf[i]].append(i) result2=[] for i in range(self.n): if len(result[i])>0: result2.append(result[i]) return result2 import sys input = lambda: sys.stdin.readline().rstrip() n, m = map(int,input().split()) s, g = map(int,input().split()) uv = [] for i in range(m): uv.append(list(map(int,input().split()))) input() I = list(map(int,input().split())) U = dsu(n + 1) for u, v in uv: if (u in I) or (v in I): continue else: U.merge(u, v) print('Yes' if U.same(s, g) else 'No')