"""# ### 谜题描述 Logical quantifiers are very useful tools for expressing claims about a set. For this problem, let's focus on the set of real numbers specifically. The set of real numbers includes zero and negatives. There are two kinds of quantifiers: universal (∀) and existential (∃). You can read more about them here. The universal quantifier is used to make a claim that a statement holds for all real numbers. For example: * ∀ x,x<100 is read as: for all real numbers x, x is less than 100. This statement is false. * ∀ x,x>x-1 is read as: for all real numbers x, x is greater than x-1. This statement is true. The existential quantifier is used to make a claim that there exists some real number for which the statement holds. For example: * ∃ x,x<100 is read as: there exists a real number x such that x is less than 100. This statement is true. * ∃ x,x>x-1 is read as: there exists a real number x such that x is greater than x-1. This statement is true. Moreover, these quantifiers can be nested. For example: * ∀ x,∃ y,x= 2: count_line = lines[0] quant_line = lines[1].upper() if count_line.isdigit() and len(quant_line) == int(count_line) and all(c in 'AE' for c in quant_line): return (int(count_line), quant_line) # 尝试单行格式,例如 "1 EA" if len(lines) == 1: parts = lines[0].split() if len(parts) == 2 and parts[0].isdigit() and len(parts[1]) == int(parts[0]): quant = parts[1].upper() if all(c in 'AE' for c in quant): return (int(parts[0]), quant) return None @classmethod def _verify_correction(cls, solution, identity): # 获取参考解 ref_sol = cls.reference_solution(identity) # 处理无解情况 if isinstance(ref_sol, int): return solution == -1 # 处理有解情况 return solution == ref_sol @classmethod def reference_solution(cls, identity): # 完全复制参考代码逻辑 def toposort(graph): n = len(graph) res = [] found = [0]*n for i in range(n): if found[i]: continue stack = [i] while stack: node = stack.pop() if node < 0: res.append(~node) elif not found[node]: found[node] = 1 stack.append(~node) for nei in graph[node]: if not found[nei]: stack.append(nei) # Check cycle found = [0]*n for node in res: if found[node]: return None stack = [node] found[node] = 1 while stack: current = stack.pop() for nei in graph[current]: if found[nei]: return None if not found[nei]: found[nei] = 1 stack.append(nei) return res[::-1] n = identity['n'] edges = identity['edges'] coupl1 = [[] for _ in range(n)] coupl2 = [[] for _ in range(n)] for j, k in edges: u = j - 1 v = k - 1 coupl1[u].append(v) coupl2[v].append(u) order = toposort(coupl1) if order is None: return -1 seen1 = list(range(n)) seen2 = list(range(n)) for node in order: for nei in coupl1[node]: if seen1[nei] > seen1[node]: seen1[nei] = seen1[node] for node in reversed(order): for nei in coupl2[node]: if seen2[nei] > seen2[node]: seen2[nei] = seen2[node] seen = [(seen1[i] == i and seen2[i] == i) for i in range(n)] count = sum(seen) if count == 0: return -1 quant = ''.join('A' if c else 'E' for c in seen) return (count, quant)