B. Not Afraid——Codeforces Round #406 (Div. 2)

作者: qwq 分类: ACM 发布时间: 2017-03-29 18:31
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them.

There are n parallel universes participating in this event (n Ricks and n Mortys). I. e. each of n universes has one Rick and one Morty. They’re gathering in m groups. Each person can be in many groups and a group can contain an arbitrary number of members.

Ricks and Mortys have registered online in these groups. So, a person can have joined a group more than once (developer of this website hadn’t considered this possibility).

Summer from universe #1 knows that in each parallel universe (including hers) exactly one of Rick and Morty from that universe is a traitor and is loyal, but no one knows which one. She knows that we are doomed if there’s a group such that every member in that group is a traitor (they will plan and destroy the world).

Summer knows that if there’s a possibility that world ends (there’s a group where all members are traitors) she should immediately cancel this event. So she wants to know if she should cancel the event. You have to tell her yes if and only if there’s at least one scenario (among all 2n possible scenarios, 2 possible scenarios for who a traitor in each universe) such that in that scenario the world will end.

Input

The first line of input contains two integers n and m (1 ≤ n, m ≤ 104) — number of universes and number of groups respectively.

The next m lines contain the information about the groups. i-th of them first contains an integer k (number of times someone joined i-th group, k > 0) followed by k integers vi, 1, vi, 2, …, vi, k. If vi, j is negative, it means that Rick from universe number  - vi, j has joined this group and otherwise it means that Morty from universe number vi, j has joined it.

Sum of k for all groups does not exceed 104.

Output

In a single line print the answer to Summer’s question. Print “YES” if she should cancel the event and “NO” otherwise.

Examples
input
4 2
1 -3
4 -2 3 2 -3
output
YES
input
5 2
5 3 -2 1 -1 5
3 -5 2 5
output
NO
input
7 2
3 -1 6 7
7 -5 4 2 4 7 -3 4
output
YES
Note

In the first sample testcase, 1st group only contains the Rick from universe number 3, so in case he’s a traitor, then all members of this group are traitors and so Summer should cancel the event.

很简单的一个题,下面是代码:

#include<iostream>
#include<fstream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cstdio>

using namespace std;

	
int main(){
	ios::sync_with_stdio(false);
	int a,b;

	
	cin>>a>>b;
	
	for(int i=0;i<b;i++){
			int q[10010]={0};
	int vis[20020]={0};
		int c;
		cin>>c;
		int m;
		for(int j=0;j<c;j++){
			cin>>m;
			if(m>0&&vis[10010+m]==0){
				q[m]+=1;
				vis[10010+m]=1;
				
			}
			if(m<0&&vis[10010+m]==0){
				q[-m]+=1;
				vis[10010+m]=1;
			}
			
		}
		bool y=true;
		for(int j=0;j<=a;j++){
			
			if(q[j]==2){
				y=false;
				break;
			}
		}
		if(y==true){
			cout<<"YES"<<endl;
			return 0;
		}
		
	}
	cout<<"NO"<<endl;
	
	
	return 0;
} 

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注