307353: CF1344C. Quantifier Question

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Quantifier Question

题意翻译

- 有两种符号:「任意」( $\forall$ )和「存在」( $\exists$ )。 - 记 $f(x_1,⋯,x_n)=(x_{j_1}<x_{k_1})∧(x_{j_2}<x_{k_2})∧⋯∧(x_{j_m}<x_{k_m})$,其中 $j_1,j_2,⋯,j_m,k_1,k_2,⋯,k_m$ 均为给定正整数,$∧$ 表示与运算。 - 你需要给 $Q_1,Q_2,⋯,Q_n$ 分配符号( $\forall$ 或 $\exists$ ),使得 $Q_1x_1,Q_2x_2,…,Q_nx_n,f(x_1,…,x_n)$ 始终为**真**,且「任意」( $\forall$ )符号个数最多。求出**最多的个数**及**相应方案(任意一种即可)**。**如果无论怎样分配都不成立,输出 $-1$**。**注意 $\forall x_1,\exists x_2$ 和 $\exists x_2,\forall x_1$ 是不同的(即符号之间存在顺序)**。 - 「任意」( $\forall$ )符号举例: $\forall X ,X < 100$(对于任意实数 $X$,有 $X<100$),这句话是假的。 $\forall X ,X < X+1$(对于任意实数 $X$,有 $X<X+1$),这句话是真的。 - 「存在」( $\exists$ )符号举例: $\exists X ,X < 100$(存在实数 $X$,有 $X<100$),这句话是真的。 $\exists X ,X < X-1$(存在实数 $X$,有 $X<X-1$),这句话是假的。

题目描述

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 ( $ \forall $ ) and existential ( $ \exists $ ). You can read more about them <a>here</a>. The universal quantifier is used to make a claim that a statement holds for all real numbers. For example: - $ \forall x,x<100 $ is read as: for all real numbers $ x $ , $ x $ is less than $ 100 $ . This statement is false. - $ \forall 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: - $ \exists x,x<100 $ is read as: there exists a real number $ x $ such that $ x $ is less than $ 100 $ . This statement is true. - $ \exists 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: - $ \forall x,\exists y,x<y $ is read as: for all real numbers $ x $ , there exists a real number $ y $ such that $ x $ is less than $ y $ . This statement is true since for every $ x $ , there exists $ y=x+1 $ . - $ \exists y,\forall x,x<y $ is read as: there exists a real number $ y $ such that for all real numbers $ x $ , $ x $ is less than $ y $ . This statement is false because it claims that there is a maximum real number: a number $ y $ larger than every $ x $ . Note that the order of variables and quantifiers is important for the meaning and veracity of a statement. There are $ n $ variables $ x_1,x_2,\ldots,x_n $ , and you are given some formula of the form $ f(x_1,\dots,x_n):=(x_{j_1}<x_{k_1})\land (x_{j_2}<x_{k_2})\land \cdots\land (x_{j_m}<x_{k_m}), $ where $ \land $ denotes logical AND. That is, $ f(x_1,\ldots, x_n) $ is true if every inequality $ x_{j_i}<x_{k_i} $ holds. Otherwise, if at least one inequality does not hold, then $ f(x_1,\ldots,x_n) $ is false. Your task is to assign quantifiers $ Q_1,\ldots,Q_n $ to either universal ( $ \forall $ ) or existential ( $ \exists $ ) so that the statement $ Q_1 x_1, Q_2 x_2, \ldots, Q_n x_n, f(x_1,\ldots, x_n) $ is true, and <span class="tex-font-style-bf">the number of universal quantifiers is maximized</span>, or determine that the statement is false for every possible assignment of quantifiers. **Note that the order the variables appear in the statement is fixed.** For example, if $ f(x_1,x_2):=(x_1<x_2) $ then you are not allowed to make $ x_2 $ appear first and use the statement $ \forall x_2,\exists x_1, x_1<x_2 $ . If you assign $ Q_1=\exists $ and $ Q_2=\forall $ , it will only be interpreted as $ \exists x_1,\forall x_2,x_1<x_2$.

输入输出格式

输入格式


The first line contains two integers $ n $ and $ m $ ( $ 2\le n\le 2\cdot 10^5 $ ; $ 1\le m\le 2\cdot 10^5 $ ) — the number of variables and the number of inequalities in the formula, respectively. The next $ m $ lines describe the formula. The $ i $ -th of these lines contains two integers $ j_i $ , $ k_i $ ( $ 1\le j_i,k_i\le n $ , $ j_i\ne k_i $ ).

输出格式


If there is no assignment of quantifiers for which the statement is true, output a single integer $ -1 $ . Otherwise, on the first line output an integer, the maximum possible number of universal quantifiers. On the next line, output a string of length $ n $ , where the $ i $ -th character is "A" if $ Q_i $ should be a universal quantifier ( $ \forall $ ), or "E" if $ Q_i $ should be an existential quantifier ( $ \exists $ ). All letters should be upper-case. If there are multiple solutions where the number of universal quantifiers is maximum, print any.

输入输出样例

输入样例 #1

2 1
1 2

输出样例 #1

1
AE

输入样例 #2

4 3
1 2
2 3
3 1

输出样例 #2

-1

输入样例 #3

3 2
1 3
2 3

输出样例 #3

2
AAE

说明

For the first test, the statement $ \forall x_1, \exists x_2, x_1<x_2 $ is true. Answers of "EA" and "AA" give false statements. The answer "EE" gives a true statement, but the number of universal quantifiers in this string is less than in our answer. For the second test, we can show that no assignment of quantifiers, for which the statement is true exists. For the third test, the statement $ \forall x_1, \forall x_2, \exists x_3, (x_1<x_3)\land (x_2<x_3) $ is true: We can set $ x_3=\max\{x_1,x_2\}+1 $ .

Input

题意翻译

- 有两种符号:「任意」( $\forall$ )和「存在」( $\exists$ )。 - 记 $f(x_1,⋯,x_n)=(x_{j_1}<x_{k_1})∧(x_{j_2}<x_{k_2})∧⋯∧(x_{j_m}<x_{k_m})$,其中 $j_1,j_2,⋯,j_m,k_1,k_2,⋯,k_m$ 均为给定正整数,$∧$ 表示与运算。 - 你需要给 $Q_1,Q_2,⋯,Q_n$ 分配符号( $\forall$ 或 $\exists$ ),使得 $Q_1x_1,Q_2x_2,…,Q_nx_n,f(x_1,…,x_n)$ 始终为**真**,且「任意」( $\forall$ )符号个数最多。求出**最多的个数**及**相应方案(任意一种即可)**。**如果无论怎样分配都不成立,输出 $-1$**。**注意 $\forall x_1,\exists x_2$ 和 $\exists x_2,\forall x_1$ 是不同的(即符号之间存在顺序)**。 - 「任意」( $\forall$ )符号举例: $\forall X ,X < 100$(对于任意实数 $X$,有 $X<100$),这句话是假的。 $\forall X ,X < X+1$(对于任意实数 $X$,有 $X<X+1$),这句话是真的。 - 「存在」( $\exists$ )符号举例: $\exists X ,X < 100$(存在实数 $X$,有 $X<100$),这句话是真的。 $\exists X ,X < X-1$(存在实数 $X$,有 $X<X-1$),这句话是假的。

加入题单

上一题 下一题 算法标签: