CodeForces156B、Suspects(思维+逻辑)

B. Suspects

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

As Sherlock Holmes was investigating a crime, he identified n suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from 1 to n. After that, he asked each one: "Which one committed the crime?". Suspect number i answered either "The crime was committed by suspect number ai", or "Suspect number ai didn't commit the crime". Also, the suspect could say so about himself (ai = i).

Sherlock Holmes understood for sure that exactly m answers were the truth and all other answers were a lie. Now help him understand this: which suspect lied and which one told the truth?

Input

The first line contains two integers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ n) — the total number of suspects and the number of suspects who told the truth. Next n lines contain the suspects' answers. The i-th line contains either "+ai" (without the quotes), if the suspect number i says that the crime was committed by suspect number ai, or "-ai" (without the quotes), if the suspect number i says that the suspect number aididn't commit the crime (ai is an integer, 1 ≤ ai ≤ n).

It is guaranteed that at least one suspect exists, such that if he committed the crime, then exactly m people told the truth.

Output

Print n lines. Line number i should contain "Truth" if suspect number i has told the truth for sure. Print "Lie" if the suspect number i lied for sure and print "Not defined" if he could lie and could tell the truth, too, depending on who committed the crime.

Examples

input

Copy

1 1
+1

output

Copy

Truth

input

Copy

3 2
-1
-2
-3

output

Copy

Not defined
Not defined
Not defined

input

Copy

4 1
+2
-3
+4
-1

output

Copy

Lie
Not defined
Lie
Not defined

Note

The first sample has the single person and he confesses to the crime, and Sherlock Holmes knows that one person is telling the truth. That means that this person is telling the truth.

In the second sample there are three suspects and each one denies his guilt. Sherlock Holmes knows that only two of them are telling the truth. Any one of them can be the criminal, so we don't know for any of them, whether this person is telling the truth or not.

In the third sample the second and the fourth suspect defend the first and the third one. But only one is telling the truth, thus, the first or the third one is the criminal. Both of them can be criminals, so the second and the fourth one can either be lying or telling the truth. The first and the third one are lying for sure as they are blaming the second and the fourth one.

 

一、原题地址

点我传送

 

二、大致题意

现在有 n 个人在录口供,明确的是在场有 m 个人说了真话,其他人说的是假话。场上有一个凶手。接着给出 n 人的口供。

+ X  表示第 i 个人说第 X 个人是凶手。

- X  表示第 i 个人说第 X 个人不是凶手。

 

三、大致思路

用一个 a[ ]来记录每个人 i 被指认的次数。如a[2]=3表示第2个人被3个人认为是凶手。

用一个b [ ]来记录每个人i 被洗白的次数。如b [2]=3表示第2个人被3个人认为不是凶手。

同时用一个cnt来记录场上洗白别人的人数,即负数的个数。

现在来枚举第 i 人是凶手的情况(注意!不是枚举谁在说谎),可以利用上面的三个数据来快速找出当前情况下说真话的人数a[ i ]+(cnt-b[ i ])。如果这个数字等于给定的 m。则说明第 i 人是凶手的情况是可以成立的。此时,我们先把他记录下来。

O(n)地处理出所有的凶手人选之后。如果凶手人选的数量等于0,那么说明所有人的供词都是模糊的。

如果凶手人选只有一个,那么那个人必定就是凶手,确定凶手后再o(n)的遍历每个人说的话判断真假就行。

如果凶手的人选可以是多个,那么也可以O(n)的去遍历每个人说的话,如果他们指认的人在备选的范围内则是不确定的,若不在备选范围内那么这个人肯定是在说谎。洗白的人判断也是差不多的,如果想要洗白的人在凶手的备选范围,我们还是无法确认,但如果不在凶手备选范围,那么他说的一定是真话了。

 

四、代码

#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<unordered_set>
#include<vector>
using namespace std;
const int inf = 0x3f3f3f3f;
typedef long long LL;
const double eps = 1e-6;


int n, m;
set<int>ss;
int talk[100005];
int a[100005], b[100005];
int cnt_fu;
int main()
{
	scanf("%d %d", &n, &m);
	cnt_fu = 0;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &talk[i]);
		if (talk[i] > 0)
		{
			a[talk[i]]++;
		}
		else 
		{
			b[-talk[i]]++;
			cnt_fu++;
		}
	}
	for (int i = 1; i <= n; i++)
	{
		if (a[i] + cnt_fu - b[i] == m)ss.insert(i);
	}
	if (ss.size() == 0)
	{
		for (int i = 1; i <= n; i++)printf("Not defined\n");
	}
	else if (ss.size() == 1)
	{
		int crime = *ss.begin();
		for (int i = 1; i <= n; i++)
		{
			if (talk[i] > 0)
			{
				if (talk[i] == crime)printf("Truth\n");
				else printf("Lie\n");
			}
			else
			{
				if (-talk[i] == crime)printf("Lie\n");
				else printf("Truth\n");
			}
		}
	}
	else
	{
		for (int i = 1; i <= n; i++)
		{
			if (talk[i] > 0)
			{
				if (ss.count(talk[i])==1)printf("Not defined\n");
				else printf("Lie\n");
			}
			else
			{
				if (ss.count(-talk[i]) == 1)printf("Not defined\n");
				else printf("Truth\n");
			}
		}
	}
	getchar();
	getchar();
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值