結果
問題 | No.2780 The Bottle Imp |
ユーザー | rlangevin |
提出日時 | 2024-06-07 23:37:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 296 ms / 2,000 ms |
コード長 | 2,646 bytes |
コンパイル時間 | 282 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 141,028 KB |
最終ジャッジ日時 | 2024-06-08 10:39:02 |
合計ジャッジ時間 | 8,850 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
52,352 KB |
testcase_01 | AC | 35 ms
52,096 KB |
testcase_02 | AC | 35 ms
52,480 KB |
testcase_03 | AC | 35 ms
52,736 KB |
testcase_04 | AC | 35 ms
52,224 KB |
testcase_05 | AC | 35 ms
52,224 KB |
testcase_06 | AC | 37 ms
52,224 KB |
testcase_07 | AC | 176 ms
94,480 KB |
testcase_08 | AC | 206 ms
95,348 KB |
testcase_09 | AC | 195 ms
95,168 KB |
testcase_10 | AC | 210 ms
95,620 KB |
testcase_11 | AC | 177 ms
94,616 KB |
testcase_12 | AC | 268 ms
105,692 KB |
testcase_13 | AC | 263 ms
106,272 KB |
testcase_14 | AC | 182 ms
97,720 KB |
testcase_15 | AC | 183 ms
97,616 KB |
testcase_16 | AC | 165 ms
95,020 KB |
testcase_17 | AC | 158 ms
93,664 KB |
testcase_18 | AC | 190 ms
97,248 KB |
testcase_19 | AC | 185 ms
97,124 KB |
testcase_20 | AC | 187 ms
97,640 KB |
testcase_21 | AC | 156 ms
93,792 KB |
testcase_22 | AC | 141 ms
83,316 KB |
testcase_23 | AC | 160 ms
91,484 KB |
testcase_24 | AC | 187 ms
92,652 KB |
testcase_25 | AC | 234 ms
100,332 KB |
testcase_26 | AC | 156 ms
90,796 KB |
testcase_27 | AC | 173 ms
106,048 KB |
testcase_28 | AC | 179 ms
105,672 KB |
testcase_29 | AC | 194 ms
95,892 KB |
testcase_30 | AC | 125 ms
88,192 KB |
testcase_31 | AC | 246 ms
111,816 KB |
testcase_32 | AC | 240 ms
92,576 KB |
testcase_33 | AC | 255 ms
129,380 KB |
testcase_34 | AC | 296 ms
141,028 KB |
testcase_35 | AC | 118 ms
86,912 KB |
testcase_36 | AC | 37 ms
52,352 KB |
testcase_37 | AC | 36 ms
52,224 KB |
testcase_38 | AC | 119 ms
86,912 KB |
testcase_39 | AC | 224 ms
114,716 KB |
testcase_40 | AC | 233 ms
114,444 KB |
testcase_41 | AC | 222 ms
114,724 KB |
testcase_42 | AC | 36 ms
52,608 KB |
testcase_43 | AC | 35 ms
52,480 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() if 0 not in mem[0]: print("No") exit() N = len(nG) dp = [-100] * N dp[0] = 0 for i in range(N): for v in nG[i]: dp[v] = max(dp[v], dp[i] + 1) print("Yes") if max(dp) == N-1 else print("No")