8611 Daniel's Road I

Source: Internet
Author: User

Time limit : 500MS Memory limit : 1000K commits: 157 number of passes :

Question types : programming language : C + +; C

Description

To become an ACM Daniel, you need to master a lot of necessary knowledge points. Some knowledge points can be pushed to export other knowledge points, so the new problems encountered in the game, often can be derived from the knowledge that you have learned. Now the derivation of all the knowledge points and knowledge points to be mastered is given. To reduce the difficulty, assuming that the derivation of knowledge is unidirectional, even if a knowledge can directly (or indirectly) derive b knowledge, then b Knowledge is not a direct (or indirect) derivation of a knowledge. A novice wants to master all the knowledge points as soon as possible, how much knowledge does he need at least?  

Input format

The first line 0<n<=1000,0<m<n*n. . N indicates the number of knowledge points that must be mastered, number 0~n-1. m deduces The total number of relationships between knowledge points. Next m line, a b two number per line, indicating from a knowledge can deduce B Knowledge.

Output format

A number x, which indicates the minimum number of knowledge to master.

Input sample

8 4

0 1

0 2

1 3

/*this uses the C + + sort function, which can be sorted by C's Qsort .*//*Water problem, the second number is deduced, as long as the statistics of all the second number, these are not to learn, the total n-count is the result*/#include<stdio.h>#include<algorithm>using namespacestd;intMain () {inta[100000],b[100000]; intI,n,m,count=0; scanf ("%d%d",&n,&m);  for(i=0; i<m; i++) scanf ("%d%d",&a[i],&B[i]); Sort (b,b+M);/*Sort Array B*/     for(i=0; i<m; i++)/*The number of different elements in an already-lined array, B, requires a number that is not equal to its last number, count+1*/        if(b[i]!=b[i+1]) count++; printf ("%d", N-count);}
View Code

1 4

Output sample

4

Time:15ms

8611 Daniel's Road I

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.