Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

通过传递闭包的算法,环都是被求出来的,但是最后我们只累加出度和入度,无礼本身环的存在.真是一道不差的水题,水份刚刚好

Posted by gfedcba at 2009-03-02 21:13:05 on Problem 3660
In Reply To:Re:如果有环怎么办? Posted by:MasterLuo at 2008-07-22 23:37:41
        int sum = 0;
	int ans = 0;
	for (i=1; i<=n; i++)
	{
		sum = 0;
		for (j=1; j<=n; j++)
		{
			if (i == j) // 不计算本身环
			{
				continue;
			}
			// 计算出度和入度的总和
			if (matrix[i][j])
			{
				sum++;
			}
		    if (matrix[j][i])
			{
				sum++;
			}
		}
		if (sum == n-1)
		{
			ans++;
		}
	}
	cout<<ans<<endl;

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator