记录编号 |
355097 |
评测结果 |
AAAAAAAAAA |
题目名称 |
奶牛议会 |
最终得分 |
100 |
用户昵称 |
sxysxy |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.048 s |
提交时间 |
2016-11-23 19:51:17 |
内存使用 |
0.40 MiB |
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <cstdarg>
#include <cstdlib>
#include <cctype>
#include <vector>
using namespace std;
#define MAXN 4040
bool mark[MAXN];
int rec[MAXN];
int rec_top;
int n;
vector<int> G[MAXN];
void add_assert(int x, int xv, int y, int yv)
{
x = (x<<1)|xv;
y = (y<<1)|yv;
G[x^1].push_back(y);
G[y^1].push_back(x);
}
bool dfs(int x)
{
if(mark[x^1])return false;
if(mark[x])return true;
mark[x] = true;
rec[rec_top++] = x;
for(int i = 0; i < G[x].size(); i++)
if(!dfs(G[x][i]))return false;
return true;
}
inline int fast_read()
{
int r;
char c;
bool sig = false;
while(c = getchar())
{
if(c >= '0' && c <= '9')
{
r = c^0x30;
break;
}else if(c == '-')sig = true;
}
while(isdigit(c = getchar()))
r = (r<<3)+(r<<1)+(c^0x30);
return sig?-r:r;
}
int p1[MAXN];
int p2[MAXN];
int main()
{
freopen("cowngress.in", "r", stdin);
freopen("cowngress.out", "w", stdout);
int n, m;
n = fast_read();
m = fast_read();
for(int i = 0; i < m; i++)
{
char c;
int x = fast_read();
while(!isalpha(c = getchar()));
int xv = c=='Y';
int y = fast_read();
while(!isalpha(c = getchar()));
int yv = c=='Y';
add_assert(x, xv, y, yv);
}
for(int i = 1; i <= n; i++)
{
int k = i<<1;
rec_top = 0;
p1[i] = dfs(k);
while(rec_top)mark[rec[--rec_top]] = false;
rec_top = 0;
p2[i] = dfs(k^1);
while(rec_top)mark[rec[--rec_top]] = false;
if(!p1[i] && !p2[i]) //
{
puts("IMPOSSIBLE");
return 0;
}
}
for(int i = 1; i <= n; i++)
{
if(p1[i] && !p2[i])putchar('N');
else if(!p1[i] && p2[i])putchar('Y');
else if(p1[i] && p2[i])putchar('?');
}
return 0;
}