結果
問題 | No.1805 Approaching Many Typhoon |
ユーザー | Shirotsume |
提出日時 | 2022-01-12 20:34:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 53 ms / 2,000 ms |
コード長 | 2,238 bytes |
コンパイル時間 | 291 ms |
コンパイル使用メモリ | 82,360 KB |
実行使用メモリ | 68,176 KB |
最終ジャッジ日時 | 2024-11-15 15:04:54 |
合計ジャッジ時間 | 2,581 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
54,104 KB |
testcase_01 | AC | 40 ms
52,724 KB |
testcase_02 | AC | 36 ms
53,140 KB |
testcase_03 | AC | 36 ms
53,308 KB |
testcase_04 | AC | 36 ms
53,912 KB |
testcase_05 | AC | 38 ms
53,088 KB |
testcase_06 | AC | 36 ms
52,540 KB |
testcase_07 | AC | 35 ms
53,856 KB |
testcase_08 | AC | 35 ms
52,752 KB |
testcase_09 | AC | 37 ms
54,612 KB |
testcase_10 | AC | 36 ms
52,780 KB |
testcase_11 | AC | 35 ms
52,988 KB |
testcase_12 | AC | 36 ms
53,488 KB |
testcase_13 | AC | 35 ms
53,108 KB |
testcase_14 | AC | 34 ms
53,044 KB |
testcase_15 | AC | 36 ms
53,240 KB |
testcase_16 | AC | 36 ms
53,144 KB |
testcase_17 | AC | 37 ms
53,016 KB |
testcase_18 | AC | 36 ms
53,504 KB |
testcase_19 | AC | 34 ms
53,368 KB |
testcase_20 | AC | 34 ms
53,204 KB |
testcase_21 | AC | 34 ms
53,636 KB |
testcase_22 | AC | 35 ms
53,336 KB |
testcase_23 | AC | 35 ms
52,812 KB |
testcase_24 | AC | 35 ms
53,820 KB |
testcase_25 | AC | 34 ms
53,752 KB |
testcase_26 | AC | 35 ms
53,156 KB |
testcase_27 | AC | 34 ms
52,888 KB |
testcase_28 | AC | 53 ms
66,616 KB |
testcase_29 | AC | 51 ms
67,340 KB |
testcase_30 | AC | 52 ms
67,960 KB |
testcase_31 | AC | 52 ms
68,176 KB |
testcase_32 | AC | 36 ms
53,168 KB |
testcase_33 | AC | 37 ms
58,296 KB |
testcase_34 | AC | 40 ms
60,228 KB |
testcase_35 | AC | 40 ms
61,980 KB |
testcase_36 | AC | 43 ms
62,184 KB |
testcase_37 | AC | 36 ms
53,684 KB |
testcase_38 | AC | 35 ms
53,536 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() nm = list(map(str,input().split())) n = int(nm[0]) m = int(nm[1]) sg = list(map(str,input().split())) s = int(sg[0]) g = int(sg[1]) uv = [] for i in range(m): uv.append(list(map(str,input().split()))[:2]) uv[i][0] = int(uv[i][0]) uv[i][1] = int(uv[i][1]) u = int(input()) I = list(map(str,input().split()))[:u] I = list(map(int, I)) U = dsu(10 * n) 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')