CF1344C.Quantifier Question

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 here.

The universal quantifier is used to make a claim that a statement holds for all real numbers. For example:

  • x,x<100\forall x,x<100 is read as: for all real numbers xx , xx is less than 100100 . This statement is false.
  • x,x>x1\forall x,x>x-1 is read as: for all real numbers xx , xx is greater than x1x-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\exists x,x<100 is read as: there exists a real number xx such that xx is less than 100100 . This statement is true.
  • x,x>x1\exists x,x>x-1 is read as: there exists a real number xx such that xx is greater than x1x-1 . This statement is true.

Moreover, these quantifiers can be nested. For example:

  • x,y,x<y\forall x,\exists y,x<y is read as: for all real numbers xx , there exists a real number yy such that xx is less than yy . This statement is true since for every xx , there exists y=x+1y=x+1 .
  • y,x,x<y\exists y,\forall x,x<y is read as: there exists a real number yy such that for all real numbers xx , xx is less than yy . This statement is false because it claims that there is a maximum real number: a number yy larger than every xx .

Note that the order of variables and quantifiers is important for the meaning and veracity of a statement.

There are nn variables x1,x2,,xnx_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(x1,,xn)f(x_1,\ldots, x_n) is true if every inequality xji<xkix_{j_i}<x_{k_i} holds. Otherwise, if at least one inequality does not hold, then f(x1,,xn)f(x_1,\ldots,x_n) is false.

Your task is to assign quantifiers Q1,,QnQ_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 the number of universal quantifiers is maximized, 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(x1,x2):=(x1<x2)f(x_1,x_2):=(x_1<x_2) then you are not allowed to make x2x_2 appear first and use the statement x2,x1,x1<x2\forall x_2,\exists x_1, x_1<x_2 . If you assign Q1=Q_1=\exists and Q2=Q_2=\forall , it will only be interpreted as x1,x2,x1<x2\exists x_1,\forall x_2,x_1<x_2.

输入格式

The first line contains two integers nn and mm ( 2n21052\le n\le 2\cdot 10^5 ; 1m21051\le m\le 2\cdot 10^5 ) — the number of variables and the number of inequalities in the formula, respectively.

The next mm lines describe the formula. The ii -th of these lines contains two integers jij_i , kik_i ( 1ji,kin1\le j_i,k_i\le n , jikij_i\ne k_i ).

输出格式

If there is no assignment of quantifiers for which the statement is true, output a single integer 1-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 nn , where the ii -th character is "A" if QiQ_i should be a universal quantifier ( \forall ), or "E" if QiQ_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 x1,x2,x1<x2\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 x1,x2,x3,(x1<x3)(x2<x3)\forall x_1, \forall x_2, \exists x_3, (x_1<x_3)\land (x_2<x_3) is true: We can set x3=max{x1,x2}+1x_3=\max\{x_1,x_2\}+1 .

首页