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