题目链接:​​点击打开链接​


A. PolandBall and Hypothesis



time limit per test



memory limit per test



input



output



There exists such a positive integer n that for each positive integer m number n·m + 1".

n.



Input



n (1 ≤ n ≤ 1000) — number from the PolandBall's hypothesis.



Output



m that n·m + 1 is not a prime number. Your answer will be considered correct if you output any suitable m such that1 ≤ m ≤ 103. It is guaranteed the the answer exists.



Examples



input



3



output



1



input



4



output



2



Note



1 that has no positive divisors other than 1

3·1 + 1 = 4. We can output 1.

4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, m = 2 is okay since 4·2 + 1 = 9, which is not a prime number.






#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n;
bool shu[1000020]={1,1};
void get()
{
for(int i=2;i<=1000010;i++)
{
if(shu[i]) continue;
for(int j=i*2;j<=1000010;j+=i)
{
shu[j]=1;
}
}
}
int main()
{
get();
while(~scanf("%d",&n))
{
int i;
for(i=1;i<=1000;i++)
{
if(shu[n*i+1])
break;
}
printf("%d\n",i);
}
return 0;
}


题目链接:

​点击打开链接​


B. PolandBall and Game



time limit per test



memory limit per test



input



output



PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.

You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if both play optimally?



Input



n and m (1 ≤ n, m ≤ 103) — number of words PolandBall and EnemyBall know, respectively.

n

m

cannot know a word more than once (strings are unique), but some words can

500



Output



YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.



Examples



input



5 1 polandball is a cool character nope



output



YES



input



2 2 kremowka wadowicka kremowka wiedenska



output



YES



input



1 2 a a b



output



NO



Note



In the first example PolandBall knows much more words and wins effortlessly.

kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only saywiedenska. PolandBall says wadowicka




大意:两个人说单词,给出每个人会背的单词数和单词。规则是:不能说已经说过的单词,如果有一方不能说出单词了,那么对方获胜。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<map>
#include<iostream>
using namespace std;
int n,m;
string str;
map<string,int> M;
int main()
{
while(~scanf("%d%d",&n,&m))
{
M.clear();
for(int i=1;i<=n;i++)
{
cin>>str;
M[str]=1;
}
int cnt=0;
for(int i=1;i<=m;i++)
{
cin>>str;
if(M[str])
cnt++;
}
if(n>m)
puts("YES");
else if(n<m)
puts("NO");
else
{
if(cnt&1)
puts("YES");
else
puts("NO");
}
}
return 0;
}


题目链接:

​点击打开链接​


C. PolandBall and Forest



time limit per test



memory limit per test



input



output


k vertices andk - 1 edges, where k is some integer. Note that one vertex is

1 to n. For each Ball i

How many trees are there in the forest?


Input



n (1 ≤ n ≤ 104) — the number of Balls living in the forest.

p1, p2, ..., pn of length n, where (1 ≤ pi ≤ n) holds and pi denotes the most distant from Ball irelative living on the same tree. If there are several most distant relatives living on the same tree, pi

p

Hacking: To hack someone, you should provide a correct forest as a test. The sequence p

n (1 ≤ n ≤ 104) — the number of Balls and the integer m (0 ≤ m < n) — the total number of edges in the forest. Then m lines should follow. The i-th of them should contain two integers ai and bi and represent an edge between vertices in which relatives ai and bi



5 3 1 2 3 4 4 5


Output



You should output the number of trees in the forest where PolandBall lives.


Interaction



From the technical side, this problem is interactive. However, it should not affect you (except hacking) since there is no interaction.


Examples



input



5 2 1 5 3 3



output



2



input



1 1



output



1


Note



1-2 3-4-5.

2

In the second sample testcase, the only possible graph is one vertex and no edges. Therefore, there is only one tree.



~~英语太渣,没读明白意思 orz

大意:有 n 个点,从 1 ~ n,先将每个点与其距离最远的点的标号给出,然后要我们求出这 n 个点有多少棵树形成的,比如第一个例子,1-2,3-4-5 有两棵树。

思路:

1、直接的,可以用并查集处理。

2、我们可以发现,与每个点距离最远的点一定是树的某个端点,题中已经规定,如果存在多个距离相同远的端点,那么取编号最小的端点。也就是说,只要某些点存在于同一棵树上,那么这棵树上的给出的最远的点只有两个。当然还有特例,就是一棵树上只有一个点


还有就是碰见了这个 Idleness limit exceeded on test1

在使用多个输出函数连续进行多次输出时,有可能发现输出错误。因为下一个数据再上一个数据还没输出完毕,还在输出缓冲区中时,下一个 printf 就把另一个数据加入输出缓冲区,结果冲掉了原来的数据,出现输出错误。 在  prinf();后加上 fflush(stdout); 强制马上输出,避免错误。当然也可以换种输出:cout 就不需要这个了

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
bool vis[10010];
int main()
{
while(~scanf("%d",&n))
{
memset(vis,0,sizeof(vis));
int cnt=0;
for(int i=1;i<=n;i++)
{
int x;
scanf("%d",&x);
if(i==x)
cnt++;
else
vis[x]=1;
}
int ans=0;
for(int i=1;i<=n;i++)
{
if(vis[i])
ans++;
}
printf("%d\n",ans/2+cnt);
fflush(stdout); // 用 cout 输出就不需要这一句了
}
return 0;
}
/* 并查集实现
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int n;
int a[10010];
int fa[10010];
int find(int x)
{
if(x==fa[x]) return x;
return fa[x]=find(fa[x]);
}
int main()
{
while(~scanf("%d",&n))
{
for(int i=1;i<=n;i++)
{
fa[i]=i;
scanf("%d",&a[i]);
}
for(int i=1;i<=n;i++)
{
int nx=find(i);
int ny=find(a[i]);
if(nx!=ny)
fa[ny]=nx;
}
int ans=0;
for(int i=1;i<=n;i++)
{
if(fa[i]==i)
ans++;
}
cout<<ans<<endl;
}
return 0;
}*/