結果
問題 | No.1983 [Cherry 4th Tune C] 南の島のマーメイド |
ユーザー | aaaaaaaaaa2230 |
提出日時 | 2022-06-21 18:55:26 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,203 ms / 4,000 ms |
コード長 | 2,202 bytes |
コンパイル時間 | 205 ms |
コンパイル使用メモリ | 82,380 KB |
実行使用メモリ | 139,316 KB |
最終ジャッジ日時 | 2024-10-14 13:20:35 |
合計ジャッジ時間 | 31,353 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,352 KB |
testcase_01 | AC | 38 ms
52,608 KB |
testcase_02 | AC | 38 ms
52,608 KB |
testcase_03 | AC | 37 ms
52,480 KB |
testcase_04 | AC | 39 ms
52,864 KB |
testcase_05 | AC | 38 ms
52,480 KB |
testcase_06 | AC | 39 ms
52,352 KB |
testcase_07 | AC | 39 ms
52,480 KB |
testcase_08 | AC | 170 ms
78,092 KB |
testcase_09 | AC | 178 ms
78,908 KB |
testcase_10 | AC | 185 ms
78,848 KB |
testcase_11 | AC | 201 ms
79,164 KB |
testcase_12 | AC | 210 ms
78,512 KB |
testcase_13 | AC | 755 ms
94,896 KB |
testcase_14 | AC | 833 ms
98,644 KB |
testcase_15 | AC | 923 ms
106,820 KB |
testcase_16 | AC | 500 ms
93,056 KB |
testcase_17 | AC | 877 ms
101,716 KB |
testcase_18 | AC | 798 ms
107,248 KB |
testcase_19 | AC | 863 ms
111,140 KB |
testcase_20 | AC | 883 ms
105,460 KB |
testcase_21 | AC | 856 ms
102,152 KB |
testcase_22 | AC | 866 ms
106,824 KB |
testcase_23 | AC | 1,162 ms
112,224 KB |
testcase_24 | AC | 1,157 ms
112,008 KB |
testcase_25 | AC | 1,203 ms
112,088 KB |
testcase_26 | AC | 1,139 ms
112,388 KB |
testcase_27 | AC | 1,145 ms
112,352 KB |
testcase_28 | AC | 1,103 ms
112,080 KB |
testcase_29 | AC | 1,093 ms
112,436 KB |
testcase_30 | AC | 1,159 ms
112,004 KB |
testcase_31 | AC | 1,197 ms
112,448 KB |
testcase_32 | AC | 1,135 ms
112,804 KB |
testcase_33 | AC | 39 ms
52,224 KB |
testcase_34 | AC | 562 ms
90,752 KB |
testcase_35 | AC | 787 ms
112,856 KB |
testcase_36 | AC | 771 ms
105,556 KB |
testcase_37 | AC | 38 ms
52,096 KB |
testcase_38 | AC | 525 ms
77,396 KB |
testcase_39 | AC | 772 ms
130,604 KB |
testcase_40 | AC | 796 ms
139,316 KB |
ソースコード
class Unionfind: def __init__(self,n): self.uf = [-1]*n def find(self,x): if self.uf[x] < 0: return x else: self.uf[x] = self.find(self.uf[x]) return self.uf[x] def same(self,x,y): return self.find(x) == self.find(y) def union(self,x,y): x = self.find(x) y = self.find(y) if x == y: return False if self.uf[x] > self.uf[y]: x,y = y,x self.uf[x] += self.uf[y] self.uf[y] = x return True def size(self,x): x = self.find(x) return -self.uf[x] def Lowlink(graph): n = len(graph) order = [-1]*n low = [n]*n par = [-1]*n vis = 0 for root in range(n): if order[root] != -1: continue q = [root] while q: now = q.pop() if now < 0: now = ~now if now == root: continue p = par[now] low[p] = min(low[p],low[now]) continue if order[now] >= 0: continue order[now] = vis low[now] = vis vis += 1 q.append(~now) check = 0 for nex in graph[now]: if par[now] == nex and check == 0: check += 1 continue elif order[nex] >= 0: if low[now] < 0 or order[nex] < low[now]: low[now] = order[nex] else: par[nex] = now q.append(nex) briges = [] for i in range(n): if par[i] < 0: continue if low[i] < 0 or low[i] > order[par[i]]: briges.append((i,par[i])) return briges n,m,q = map(int,input().split()) e = [[] for i in range(n)] for _ in range(m): u,v = [int(x)-1 for x in input().split()] e[u].append(v) e[v].append(u) briges = Lowlink(e) uf = Unionfind(n) for u,v in briges: uf.union(u,v) for _ in range(q): x,y = [int(i)-1 for i in input().split()] print("Yes" if uf.same(x,y) else "No")