結果
問題 | No.2780 The Bottle Imp |
ユーザー | rlangevin |
提出日時 | 2024-06-07 21:50:26 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,481 bytes |
コンパイル時間 | 587 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 140,388 KB |
最終ジャッジ日時 | 2024-06-08 10:29:15 |
合計ジャッジ時間 | 9,213 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,480 KB |
testcase_01 | AC | 40 ms
52,480 KB |
testcase_02 | AC | 40 ms
52,480 KB |
testcase_03 | AC | 40 ms
52,480 KB |
testcase_04 | AC | 38 ms
52,096 KB |
testcase_05 | AC | 39 ms
52,352 KB |
testcase_06 | AC | 38 ms
52,352 KB |
testcase_07 | AC | 195 ms
94,872 KB |
testcase_08 | AC | 232 ms
95,752 KB |
testcase_09 | AC | 216 ms
95,300 KB |
testcase_10 | AC | 231 ms
95,040 KB |
testcase_11 | AC | 203 ms
94,376 KB |
testcase_12 | AC | 270 ms
105,936 KB |
testcase_13 | AC | 276 ms
106,496 KB |
testcase_14 | AC | 194 ms
97,340 KB |
testcase_15 | AC | 194 ms
97,448 KB |
testcase_16 | AC | 172 ms
95,020 KB |
testcase_17 | AC | 171 ms
93,728 KB |
testcase_18 | AC | 201 ms
97,376 KB |
testcase_19 | AC | 205 ms
97,192 KB |
testcase_20 | AC | 194 ms
97,960 KB |
testcase_21 | AC | 168 ms
93,860 KB |
testcase_22 | AC | 158 ms
83,316 KB |
testcase_23 | AC | 167 ms
90,920 KB |
testcase_24 | AC | 198 ms
92,544 KB |
testcase_25 | AC | 262 ms
99,968 KB |
testcase_26 | AC | 171 ms
90,940 KB |
testcase_27 | AC | 188 ms
105,656 KB |
testcase_28 | AC | 189 ms
106,052 KB |
testcase_29 | WA | - |
testcase_30 | AC | 136 ms
88,064 KB |
testcase_31 | AC | 262 ms
111,956 KB |
testcase_32 | AC | 252 ms
92,144 KB |
testcase_33 | AC | 268 ms
129,124 KB |
testcase_34 | AC | 316 ms
140,388 KB |
testcase_35 | AC | 122 ms
87,040 KB |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | AC | 143 ms
86,912 KB |
testcase_39 | AC | 238 ms
114,604 KB |
testcase_40 | AC | 237 ms
114,724 KB |
testcase_41 | WA | - |
testcase_42 | AC | 39 ms
52,096 KB |
testcase_43 | AC | 38 ms
52,096 KB |
ソースコード
class DirectedGraph(): def __init__(self, N): self.N = N self.G = [[] for i in range(N)] self.rG = [[] for i in range(N)] self.order = [] self.used1 = [0] * N self.used2 = [0] * N self.group = [-1] * N self.label = 0 self.seen = [0] * N self.Edge = set() def add_edge(self, u, v): #多重辺は排除する if (u, v) not in self.Edge: self.G[u].append(v) self.rG[v].append(u) self.Edge.add((u, v)) def dfs(self, s): stack = [~s, s] while stack: u = stack.pop() if u >= 0: if self.used1[u]: continue self.used1[u] = 1 for v in self.G[u]: if self.used1[v]: continue stack.append(~v) stack.append(v) else: u = ~u if self.seen[u]: continue self.seen[u]= 1 self.order.append(u) def rdfs(self, s, num): stack = [s] while stack: u = stack.pop() if u >= 0: self.used2[u] = 1 self.group[u] = num for v in self.rG[u]: if self.used2[v]: continue stack.append(v) def scc(self): for i in range(self.N): if self.used1[i]: continue if i != 0: print("No") exit() self.dfs(i) for s in reversed(self.order): if self.used2[s]: continue self.rdfs(s, self.label) self.label += 1 return self.label, self.group def construct(self): nG = [set() for _ in range(self.label)] mem = [[] for i in range(self.label)] for s in range(self.N): now = self.group[s] for u in self.G[s]: if now == self.group[u]: continue nG[now].add(self.group[u]) mem[now].append(s) return nG, mem N = int(input()) G = DirectedGraph(N) for i in range(N): A = list(map(int, input().split())) M = A.pop(0) for j in range(M): G.add_edge(i, A[j]-1) G.scc() nG, mem = G.construct() print("Yes") if 0 in mem[0] else print("No")