8611 Daniel Road I

Original link: http://www.cnblogs.com/arcfat/archive/2012/10/21/2733178.html

8611 Daniel Road I

Time limit: 500MS Memory Limit: 1000K
submit: 0 Passes: 0

Questions: Programming language title: Unlimited

 

Description

To become ACM Daniel, necessary to master a lot of knowledge. Some knowledge can be deduced from other knowledge, so new problems encountered in the game, a lot of time can be derived from the knowledge you learned obtained. Now all knowledge is derived relationship between points and knowledge are given to master. In order to reduce the difficulty, it is assumed that knowledge derived relationship is unidirectional, i.e., if A knowledge directly (or indirectly) to derive knowledge B, then B is not a direct knowledge (or indirectly) A knowledge of the deduced. A novice want to master all knowledge as soon as possible, at least how much knowledge he needed to master it? 

Input

The first row 0 <n <= 1000,0 <m <n * n .. n represents the number of the necessary knowledge to grasp, numbered 0 ~ n-1. m is the total number of relationship between knowledge deduced. Subsequently m rows, AB per two lines, A represents knowledge can be deduced from knowledge B.

Output

A number x, represents the minimum knowledge to master.

 

Sample Input

8 4
0 1
0 2
1 3
1 4

 

Sample Output

4

//code show as below

 

#include<stdio.h>
#define maxsize 1000
#define must 0
#define do_not 1
int main()
{
int n,m,a,b,i,cnt=0;
int tag[maxsize]={0};
scanf("%d%d",&n,&m);
for(i=0;i<m;i++)
{
scanf("%d%d",&a,&b);
if(tag[a]==must) tag[b]=do_not;
else tag[b]=do_not;
}
for(i=0;i<n;i++)
{
if(tag[i]==must) cnt++;
}
printf("%d\n",cnt);
return 0;
}

 

Reproduced in: https: //www.cnblogs.com/arcfat/archive/2012/10/21/2733178.html

Guess you like

Origin blog.csdn.net/weixin_30597269/article/details/94789592