# URAL 2038 Minimum Vertex Cover（二分匹配）

## 2038. Minimum Vertex Cover

Time limit: 1.0 second
Memory limit: 64 MB
A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at least one vertex of the set. A minimum vertex cover is a vertex cover with minimal cardinality.
Consider a set of all minimum vertex covers of a given bipartite graph. Your task is to divide all vertices of the graph into three sets. A vertex is in set N (“Never”) if there is no minimum vertex cover containing this vertex. A vertex is in set A (“Always”) if it is a part of every minimum vertex cover of the given graph. If a vertex belongs neither to N nor to A, it goes to the set E (“Exists”).

### Input

The first line of input contains three integers nmk: the size of the first vertex set of the bipartite graph, the size of the second vertex set and the number of edges (1 ≤ nm ≤ 1000; 0 ≤k ≤ 106). Next k lines contain pairs of numbers of vertices, connected by an edge. First number denotes a vertex from the first set, second — from the second set. Vertices in each set are numbered starting from one. No pair of vertices is connected by more than one edge.

### Output

On the first line, print a sequence of n letters ‘N’, ‘E’, ‘A’ without spaces. The letter on position i corresponds to the set containing i-th vertex of the first set. The second line must contain the answer for the second vertex set in the same format.

### Sample

input output
11 9 22
1 1
1 2
1 3
1 8
1 9
2 1
2 3
3 2
3 4
4 3
4 5
5 2
5 4
5 6
6 6
6 7
7 5
7 7
8 7
9 7
10 7
11 7

AEEEEEENNNN
EEEEEEANN


#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <string>
#include <vector>
#include <queue>

#define MEM(a,x) memset(a,x,sizeof a)
#define eps 1e-8
#define MOD 10009
#define MAXN 1010
#define MAXM 100010
#define INF 99999999
#define ll __int64
#define bug cout<<"here"<<endl
#define fwrite freopen("out.txt","w",stdout)

using namespace std;

{
char ch;
int a = 0;
while((ch = getchar()) == ' ' | ch == '\n');
a += ch - '0';
while((ch = getchar()) != ' ' && ch != '\n')
{
a *= 10;
a += ch - '0';
}
return a;
}

void Print(int a)
{
if(a>9)
Print(a/10);
putchar(a%10+'0');
}
int n,m,k;
vector<int> vec[MAXN];
int mp[MAXN][MAXN];
char ch[]="NEA";
int dfs(int u)
{
int sz=vec[u].size();
for(int i=0;i<sz;i++)
{
int v=vec[u][i];
if(!vis[v])
{
vis[v]=1;
{
return 1;
}
}
}
return 0;
}

void hungary()
{
for(int i=1;i<=n;i++)
{
MEM(vis,0);
dfs(i);
}
}

int main()
{
while(scanf("%d%d%d",&n,&m,&k)!=EOF)
{
for(int i=1;i<=n;i++) vec[i].clear();
MEM(mp,0);
while(k--)
{
int u,v;
scanf("%d%d",&u,&v);
mp[u][v]=1;
vec[u].push_back(v);
}
hungary();
queue<int> que;
for(int i=1;i<=n;i++)
{
ansx[i]=0,que.push(i);
else ansx[i]=1;
}
for(int i=1;i<=m;i++)
{
ansy[i]=0,que.push(i+n);
else ansy[i]=1;
}
while(!que.empty())
{
int i=que.front(); que.pop();
if(i<=n)
{
int u=i;
for(int v=1;v<=m;v++)
{
if(mp[u][v])
{
ansy[v]=2;
if(ansx[tmp]) que.push(tmp);
ansx[tmp]=0;
}
}
}
else
{
int v=i-n;
for(int u=1;u<=n;u++)
{
if(mp[u][v])
{
ansx[u]=2;
if(ansy[tmp]!=0) que.push(tmp+n);
ansy[tmp]=0;
}
}
}
}
for(int i=1;i<=n;++i)
putchar(ch[ansx[i]]);
puts("");
for(int i=1;i<=m;++i)
putchar(ch[ansy[i]]);
puts("");
}
return 0;
}