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<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.
∃y,∀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 x1,x2,…,xn, and you are given some formula of the form
f(x1,…,xn):=(xj1<xk1)∧(xj2<xk2)∧⋯∧(xjm<xkm),
where ∧ denotes logical AND. That is, f(x1,…,xn) is true if every inequality xji<xki holds. Otherwise, if at least one inequality does not hold, then f(x1,…,xn) is false.

Your task is to assign quantifiers Q1,…,Qn to either universal (∀) or existential (∃) so that the statement
Q1x1,Q2x2,…,Qnxn,f(x1,…,xn)
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) then you are not allowed to make x2 appear first and use the statement ∀x2,∃x1,x1<x2. If you assign Q1=∃ and Q2=∀, it will only be interpreted as ∃x1,∀x2,x1<x2.

Input
The first line contains two integers n and m (2≤n≤2⋅105; 1≤m≤2⋅105) — 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 ji,ki (1≤ji,ki≤n, ji≠ki).

Output
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 Qi should be a universal quantifier (∀), or “E” if Qi should be an existential quantifier (∃). All letters should be upper-case. If there are multiple solutions where the number of universal quantifiers is maximum, print any.

Examples

input
2 1
1 2
output
1
AE
input
4 3
1 2
2 3
3 1
output
-1
input
3 2
1 3
2 3
output
2
AAE

Note
For the first test, the statement ∀x1,∃x2,x1<x2 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) is true: We can set x3=max{x1,x2}+1.

#include<bits/stdc++.h>#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define sc(a) scahf("%c",&a);
#define ss(a) scanf("%s",a)
#define pi(a) printf("%d\n",a)
#define pl(a) printf("%lld\n",a)
#define pc(a) putchar(a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i, a, b) for(register int i=a;i<=b;++i)
#define repd(i, a, b) for(register int i=a;i>=b;--i)
#define reps(s) for(register int i=head[s];i;i=Next[i])
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<long,long>
#define pil pair<int,long>
#define pli pair<long,int>
#define mii unordered_map<int,int>
#define msi unordered_map<string,int>
#define lowbit(x) ((x)&(-(x)))
#define ce(i, r) i==r?'\n':' '
#define pb push_back
#define fi first
#define se second
#define INF 0x3f3f3f3f
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;inline int qr() {int f = 0, fu = 1;char c = getchar();while (c < '0' || c > '9') {if (c == '-')fu = -1;c = getchar();}while (c >= '0' && c <= '9') {f = (f << 3) + (f << 1) + c - 48;c = getchar();}return f * fu;
}const int N = 1e5 + 10, M = 1e5 + 10;
int head[N], ver[M << 1], Next[M << 1], tot;
int hc[N], vc[M << 1], nc[M << 1], tc;
int out[N], n, m;
bool ans[N];
bool v[N], v_c[N];inline void add(int x, int y) {ver[++tot] = y;Next[tot] = head[x];head[x] = tot;
}inline void add_c(int x, int y) {vc[++tc] = y;nc[tc] = hc[x];hc[x] = tc;
}inline void read() {n = qr(), m = qr();repi(i, 1, m) {int x = qr(), y = qr();add(x, y), add_c(y, x);out[x]++;}
}inline bool topsort() {queue<int> q;int cnt = 0;repi(i, 1, n)if (!out[i])q.push(i), cnt++;while (!q.empty()) {int x = q.front();q.pop();for (int i = hc[x]; i; i = nc[i]) {int y = vc[i];if (!--out[y])q.push(y), cnt++;}}return cnt == n;
}void dfs(int x) {v[x] = true;reps(x) {int y = ver[i];if (v[y])continue;dfs(y);}
}void dfs_c(int x) {v_c[x] = true;for (int i = hc[x]; i; i = nc[i]) {int y = vc[i];if (v_c[y])continue;dfs_c(y);}
}int main() {read();if (!topsort()) {puts("-1");return 0;}int cnt = 0;repi(i, 1, n) {if (!v[i] && !v_c[i])ans[i] = true, cnt++;if (!v[i])dfs(i);if (!v_c[i])dfs_c(i);}pi(cnt);repi(i, 1, n)pc(ans[i] ? 'A' : 'E');return 0;
}

Quantifier Question相关推荐

  1. CodeForces - 1345E Quantifier Question(dfs实现拓扑序)

    题目链接:点击查看 题目大意:给出 n 个变量以及 m 个不等式,要求给 n 个变量分配作用域,使得所有不等式成立的前提下,"所有"的出现次数最多,给出一种构造方案 题目分析:因为 ...

  2. Question: Short And Long Read Sequencing

    Question: Short And Long Read Sequencing What is the difference between short and long read sequenci ...

  3. 090901 T 面试中遇到的一个Sql Question

    10k的面试中遇到的一个Sql Question,当时没有做完整,后来回到易车工作的时候又遇到这个问题,结果同事都没做出来. 问题: 表: Category: ID Name Items: ID Ca ...

  4. Quora Question Pairs 项目参考资料

    实现多种解决方案的 kaggle比赛--Quora Question Pairs https://blog.csdn.net/qq_27009517/article/details/87716641? ...

  5. https://www.zhihu.com/question/41564604

    flask 与django区别 https://www.zhihu.com/question/41564604

  6. A Context-aware Attention Network for Interactive Question Answering--阅读笔记

    论文来源:2017 KDD 论文链接 ABSTRACT INTRODUCTION 背景 现存模型的限制 解决方案 贡献 RELATED WORK GATED RECURRENT UNIT NETWOR ...

  7. 开源 java CMS - FreeCMS2.8 数据对象 question

    项目地址:http://www.freeteam.cn/ question 在使用 网上调查相关标签时,标签会封装question供页面调用. 属性 说明 id id selectnum 此网上调查下 ...

  8. 今天收到上海某公司的全英文笔试题(some question of interview )

    Interview email questions are in 4 categories. We look for candidates who give good responses in any ...

  9. Java Programming Test Question 3

    import java.util.HashSet;public class JPTQuestion3 {public static void main(String[] args) {HashSet ...

最新文章

  1. [转]Installing Memcached on Windows
  2. Query-digest-UI监控慢查询,以及此工具的改进版
  3. 任务调度及远端管理(基于Quartz.net)
  4. php 编码规范哪些_整理了一份比较全面的PHP开发编码规范.
  5. Python编程基础19:封装、继承与多态
  6. PyTorch 1.0 中文官方教程:使用 Amazon AWS 进行分布式训练
  7. vue动态class类型
  8. ansible 之条件语句 when
  9. VB中字符串匹配的多种方式
  10. eventlistener java_EventListener原理
  11. echarts 关系图 参数_Echarts关系图(使用重力图)
  12. webstorm主题配置
  13. Unity 2D独立开发手记(外篇):Anima2D动画制作
  14. O2O两种典型运作模式结合案例分析
  15. 异方差及stata命令
  16. OSPF三种验证配置
  17. s3cmd安装配置及基础命令
  18. WORD如何取消默认的分栏
  19. 有必要升级到php7,升级到 PHP 7.4
  20. Tikz 画图技巧二

热门文章

  1. leetcode:72. 编辑距离
  2. 北大智航杯竞赛仿真环境基础配置(对应PX4 1.13版)
  3. 如何检查域名解析是否生效
  4. java将数字格式化为万或者千亿或者 以亿为单位
  5. 【干货】Chrome插件(扩展)开发全攻略(转载)
  6. 人体三维重构论文集合:awesome 3d human reconstruction
  7. 洛谷P1049: 装箱问题
  8. 有关SEI 补充增强信息
  9. 人工智能对联生成 API 数据接口
  10. m基于Berlekamp-Massey钱搜索算法的BCH译码误码率matlab仿真