比赛 9.6 评测结果 W
题目名称 真正的说谎者 最终得分 0
用户昵称 ┭┮﹏┭┮ 运行时间 0.010 s
代码语言 C++ 内存使用 9.01 MiB
提交时间 2024-09-06 21:55:01
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 1e5+10;

ll read(){
	ll x = 0,f = 1;char c = getchar();
	for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
	for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
	return x * f;
}


int n,m,q;
struct DSU{
	int fa[N],siz[N];
	void build(){for(int i = 1;i <= (m + q) * 2;i++)fa[i] = i,siz[i] = 1;}
	int find(int x){return x == fa[x] ? x : fa[x] = find(fa[x]);}
	bool merge(int x,int y){
		x = find(x),y = find(y);
		if(x == y)return 1;
		siz[y] += siz[x];
		return fa[x] = y,0;
	}
}U;


char op[10];
bool f[1010][310][2];
pii la[1010][310][2];
int now[1010],s[2010];
vector<int>ans;
set<int>su;
void work(){
	U.build();
	for(int i = 1;i <= n;i++){
		int x = read(),y = read();
		scanf("%s",op);
		if(op[0] == 'n')U.merge(x,y + q + m),U.merge(x + q + m,y);
		else U.merge(x,y),U.merge(x + q + m,y + q + m);
	}
	for(int i = 1;i <= m + q;i++)
		if(U.find(i) == U.find(i + q + m))return printf("no\n"),void();
	memset(s,0,sizeof s);
	for(int i = 1;i <= m + q;i++)s[U.find(i)]++;
	int cnt = 0;
	memset(f,0,sizeof f);
	memset(la,0,sizeof la);
	f[0][0][0] = 1;
	for(int x = 1;x <= m + q;x++){
		if(x != U.find(x))continue;
		cnt++;
		now[cnt] = x;
		int val = s[x];
		for(int i = val;i <= m;i++){
			if(f[cnt-1][i - val][0]){
				la[cnt][i][0] = {i - val,0};
				f[cnt][i][0] = 1;
			}
			else if(f[cnt-1][i - val][1]){
				la[cnt][i][0] = {i - val,1};
				f[cnt][i][0] = 1;
			}
		}
		val = s[x + q + m];
		for(int i = val;i <= m;i++){
			if(f[cnt-1][i - val][0]){
				la[cnt][i][1] = {i - val,0};
				f[cnt][i][1] = 1;
			}
			else if(f[cnt-1][i - val][1]){
				la[cnt][i][1] = {i - val,1};
				f[cnt][i][1] = 1;
			}
		}
	}
	if((!f[cnt][m][0] && !f[cnt][m][1]) || (f[cnt][m][0] && f[cnt][m][1]))return printf("no\n"),void();
	ans.clear(),su.clear();
	pii x = f[cnt][m][0] ?	mp(m,0) : mp(m,1);
	for(int i = cnt;i >= 1;i--){
		if(x.se == 0)su.insert(now[i]);
		else su.insert(now[i] + q + m);
		x = la[cnt][x.fi][x.se];
	}
	for(int i = 1;i <= m + q;i++)	
		if(su.find(U.find(i)) != su.end())printf("%d\n",i);
	printf("end\n");
}
int main(){
	freopen("trueliars.in","r",stdin);
	freopen("trueliars.out","w",stdout);
	while(1){
		n = read(),m = read(),q = read();
		if(!n)break;
		work();
	}

	return 0;

}