Codevs 2833 Strange Dreams

Source: Internet
Author: User

time limit: 1 sspace limit: 128000 KBtitle level: Golden GoldTitle Description Description

Aiden was caught in a strange dream: he was trapped in a small house with buttons on the wall and a screen showing some information. The screen said that to press all the buttons to go out, and give some information, indicating that a button can only be pressed after the other button, and the button is not mentioned can be pressed at any time. But Aiden found that the information on the screen seems to be contradictory, please help to judge.

Enter a description Input Description

The first line, two number n,m, indicates that there is a number of 1 ... n these n buttons, the screen has m message.

The next M-line, two number Ai,bi per line, indicates that the BI button is pressed after the AI. The information given may be duplicated and guaranteed to be ai≠bi.

Output description Output Description

If the button can be pressed all, the output "O (∩_∩) o".

If not, the first line outputs "t_t", and the second line outputs the number of buttons that cannot confirm the order of the press because of conflicting information. The output does not include quotation marks.

Sample input Sample Input

3 3

1 2

2 3

3 2

Sample output Sample Output

t_t

2

Data range and Tips Data Size & Hint

For 30% of data, ensure 0

For 50% of data, ensure 0

For 70% of data, ensure 0

For 100% of data, ensure 0

#include <iostream>#include<cstdio>#include<cstring>#include<queue>using namespacestd;intru[10001]={0};intmap[10001][10001]={0};intMain () {memset (Ru,0,sizeofru); intN,m,ai,bi; scanf ("%d%d",&n,&m);  for(intI=1; i<=m;i++) {cin>>ai>>bi;ru[bi]++;map[ai][bi]=1; }    intans=0;  for(intI=1; i<=n;i++)    {        intt=0;  for(intj=1; j<=n;j++)            if(!Ru[j]) {T=j; Break; }                     if(t) ans++; Else  Break;  for(intj=1; j<=n;j++)         if(Map[t][j]) ru[j]--; Ru[t]=0x7fffffff; }            if(ans==n) cout<<"o (∩_∩) o"; Elsecout<<"t_t"<<endl<<n-ans; return 0;}

Idea: Topological sort ~ ~ ~

Codevs 2833 Strange Dreams

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.