CUC-SUMMER-6-C

C - Not Afraid
CodeForces - 787B

Since the giant heads have appeared in the sky all humanity is in danger, so allRicks 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,?jhas 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.

Example
Input
4 21 -34 -2 3 2 -3

Output
YES

Input
5 25 3 -2 1 -1 53 -5 2 5

Output
NO

Input
7 23 -1 6 77 -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.


題意:如果每一組中至少存在一對相反數(shù)則輸出no,否則輸出yes

解法:用set來存儲,對于一個數(shù)n如果-n在set中,則這一組合格藻烤,所有組都合格則輸出No

代碼:

#include<iostream>
#include<set>
using namespace std;
int main()
{
    int n,m,k;
    cin>>n>>m;
    set<int> s;
    int ans=1;
    for(int i=0;i<m;i++){
        s.clear();
        cin>>k;
        int v;
        int flag=0;
        for(int j=0;j<k;j++){
            cin>>v;
            if(s.count(-v))
                flag=1;
            s.insert(v);
        }
        ans=ans&flag;
    }
    ans?cout<<"NO"<<endl:cout<<"YES"<<endl;
    return 0;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市嵌言,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌愧怜,老刑警劉巖呀页,帶你破解...
    沈念sama閱讀 218,607評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異拥坛,居然都是意外死亡蓬蝶,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,239評論 3 395
  • 文/潘曉璐 我一進店門猜惋,熙熙樓的掌柜王于貴愁眉苦臉地迎上來丸氛,“玉大人,你說我怎么就攤上這事著摔』捍埽” “怎么了?”我有些...
    開封第一講書人閱讀 164,960評論 0 355
  • 文/不壞的土叔 我叫張陵谍咆,是天一觀的道長禾锤。 經(jīng)常有香客問我,道長摹察,這世上最難降的妖魔是什么恩掷? 我笑而不...
    開封第一講書人閱讀 58,750評論 1 294
  • 正文 為了忘掉前任,我火速辦了婚禮供嚎,結(jié)果婚禮上黄娘,老公的妹妹穿的比我還像新娘。我一直安慰自己克滴,他們只是感情好逼争,可當我...
    茶點故事閱讀 67,764評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著劝赔,像睡著了一般誓焦。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上着帽,一...
    開封第一講書人閱讀 51,604評論 1 305
  • 那天杂伟,我揣著相機與錄音竿秆,去河邊找鬼。 笑死稿壁,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的歉备。 我是一名探鬼主播傅是,決...
    沈念sama閱讀 40,347評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼蕾羊!你這毒婦竟也來了喧笔?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,253評論 0 276
  • 序言:老撾萬榮一對情侶失蹤龟再,失蹤者是張志新(化名)和其女友劉穎书闸,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體利凑,經(jīng)...
    沈念sama閱讀 45,702評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡浆劲,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,893評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了哀澈。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片牌借。...
    茶點故事閱讀 40,015評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖割按,靈堂內(nèi)的尸體忽然破棺而出膨报,到底是詐尸還是另有隱情,我是刑警寧澤适荣,帶...
    沈念sama閱讀 35,734評論 5 346
  • 正文 年R本政府宣布现柠,位于F島的核電站,受9級特大地震影響弛矛,放射性物質(zhì)發(fā)生泄漏够吩。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,352評論 3 330
  • 文/蒙蒙 一汪诉、第九天 我趴在偏房一處隱蔽的房頂上張望废恋。 院中可真熱鬧,春花似錦扒寄、人聲如沸鱼鼓。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,934評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽迄本。三九已至,卻和暖如春课竣,著一層夾襖步出監(jiān)牢的瞬間嘉赎,已是汗流浹背置媳。 一陣腳步聲響...
    開封第一講書人閱讀 33,052評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留公条,地道東北人拇囊。 一個月前我還...
    沈念sama閱讀 48,216評論 3 371
  • 正文 我出身青樓,卻偏偏與公主長得像靶橱,于是被迫代替她去往敵國和親寥袭。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,969評論 2 355

推薦閱讀更多精彩內(nèi)容