标签:一个 har 领导 必须 工作 false 投票 turn desc
#include <cstdio> #include <cstring> char buf[10000000], *ptr = buf - 1; inline int readint(){ int n = 0; while(*++ptr < ‘0‘ || *ptr > ‘9‘); while(*ptr <= ‘9‘ && *ptr >= ‘0‘) n = (n << 1) + (n << 3) + (*ptr++ & 15); return n; } const int maxn = 1000 + 10, maxm = 4000 + 10; struct Edge{ int to, next; Edge(){} Edge(int _t, int _n): to(_t), next(_n){} }e[maxm * 2]; int fir[maxn * 2] = {0}, cnt = 0; inline void add(int u, int v){ e[++cnt] = Edge(v, fir[u]); fir[u] = cnt; } int n, m; int vis[maxn * 2] = {0}, idx = 0; void dfs(int u){ vis[u] = idx; for(int v, i = fir[u]; i; i = e[i].next){ v = e[i].to; if(vis[v] != idx) dfs(v); } } inline bool Judge(int u){ idx++; dfs(u); for(int i = 1; i <= n; i++) if(vis[i] == idx && vis[i + n] == idx) return false; return true; } char ans[maxn]; int main(){ buf[fread(buf, sizeof(char), sizeof(buf), stdin)] = 0; n = readint(); m = readint(); char x, y; for(int u, v, uu, vv, i = 1; i <= m; i++){ u = readint(); while(*++ptr != ‘Y‘ && *ptr != ‘N‘); x = *ptr; if(x == ‘Y‘) uu = u + n; else{ uu = u; u = u + n; } v = readint(); while(*++ptr != ‘Y‘ && *ptr != ‘N‘); y = *ptr; if(y == ‘Y‘) vv = v + n; else{ vv = v; v = v + n; } add(uu, v); add(vv, u); } bool f1, f2; for(int i = 1; i <= n; i++){ f1 = Judge(i); f2 = Judge(i + n); if(f1 && f2) ans[i] = ‘?‘; else if(f1) ans[i] = ‘Y‘; else if(f2) ans[i] = ‘N‘; else{ puts("IMPOSSIBLE"); return 0; } } for(int i = 1; i <= n; i++) putchar(ans[i]); return 0; }
标签:一个 har 领导 必须 工作 false 投票 turn desc
原文地址:http://www.cnblogs.com/ruoruoruo/p/7635465.html