Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
通过传递闭包的算法,环都是被求出来的,但是最后我们只累加出度和入度,无礼本身环的存在.真是一道不差的水题,水份刚刚好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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator