# 分析：

$i+n表示huban{d}_{i}坐在左边$$i+n表示huband_i坐在左边$
$i+2\ast n表示wif{e}_{i}坐在右边$$i+2*n表示wife_i坐在右边$
$i+n+2\ast n表示huban{d}_{i}坐在右边$$i+n+2*n表示huband_i坐在右边$

$i->i+n+2\ast n$$i->i+n+2*n$$i+n+2\ast n->i$$i+n+2*n->i$
$i+2\ast n->i+n$$i+2*n->i+n$,$i+n->i+2\ast n$$i+n->i+2*n$

$wif{e}_{i}跟wif{e}_{j}$$wife_i跟wife_j$乱搞

$wif{e}_{i}跟husban{d}_{j}$$wife_i跟husband_j$乱搞

$husban{d}_{i}跟husban{d}_{j}$$husband_i跟husband_j$乱搞

# 代码：

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#define M 2000005
#define N 2005

using namespace std;

stack <int> st;
queue <int> Q;

struct Node {
int u, v, next;
} a[M];
int Instack[N], Belong[N], dfn[N], low[N], Ls[N], cnt, tot, num, n, m;
int Cp[N], Rd[N], Color[N];

void Addedge(int u, int v) {
cnt++;
a[cnt].u = u;
a[cnt].v = v;
a[cnt].next = Ls[u];
Ls[u] = cnt;
}

void Clear_init() {
for (int i = 0 ; i < 4 * n; i++)
Ls[i] = Rd[i] = dfn[i] = low[i] = Color[i] = Instack[i] = 0;
tot = num = cnt = 0;
}

void Tarjan(int u) {
dfn[u] = low[u] = ++num;
Instack[u] = 1;
st.push(u);
for (int i = Ls[u]; i; i = a[i].next) {
int v = a[i].v;
if (!dfn[v]){
Tarjan(v);
low[u] = min(low[u], low[v]);
}
else if (Instack[v]) low[u] = min(low[u], dfn[v]);
}
if (low[u] == dfn[u]) {
tot++;
int rp;
while ("rp++") {
rp = st.top();
st.pop();
Instack[rp] = 0;
Belong[rp] = tot;
if (rp == u) break;
}
}
}

void Top_sort() {
vector <int> E[N];
for (int i = 1; i <= cnt; i++) {
int u =a[i].u, v = a[i].v;
if (Belong[u] != Belong[v]) {
E[Belong[v]].push_back(Belong[u]);
Rd[Belong[u]]++;
}
}

for (int i = 1; i <= tot; i++)
if (!Rd[i]) Q.push(i);

while (!Q.empty()) {
int u = Q.front();
Q.pop();
if (!Color[u]) {
Color[u] = 1;
Color[Cp[u]] = 2;
}
for (int i = 0; i < E[u].size(); i++){
Rd[E[u][i]]--;
if (!Rd[E[u][i]]) Q.push(E[u][i]);
}
}
}

bool solve_problem() {
for (int i = 0; i < 4 * n; i++)
if (!dfn[i]) Tarjan(i);
for (int i = 0; i < 2 * n; i++) {
if (Belong[i] == Belong[i + 2 * n]) return 0;
Cp[Belong[i]] = Belong[i + 2 * n];
Cp[Belong[i + 2 * n]] = Belong[i];
}
Top_sort();
return 1;
}

int main() {
while (~scanf("%d %d", &n, &m)) {
if (!n && !m) break;
Clear_init();
for (int i = 1; i < n; i++) {
Addedge(i, i + n + 2 * n);
Addedge(i + n + 2 * n, i);
Addedge(i + 2 * n, i + n);
Addedge(i + n, i + 2 * n);
}
int x, y;
char aa, bb;
for (int i = 1; i <= m; i++) {
scanf("%d%c %d%c", &x, &aa, &y, &bb);
if (aa == 'h') x = x + n;
if (bb == 'h') y = y + n;
Addedge(x + 2 * n, y);
Addedge(y + 2 * n, x);
}
int count = 0;
if (solve_problem()) {
for (int i = 1; i < n; i++) {
if (Color[Belong[i]] == 1) {
printf("%dw", i);
count++;
if (count != (n - 1)) printf(" ");
else printf("\n");
} else {
printf("%dh", i);
count++;
if (count != (n - 1)) printf(" ");
else printf("\n");
}
}
}
return 0;
} 

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120