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

贴一发Bellman-Ford的0ms精简代码~

Posted by 416221843 at 2017-07-04 22:48:49 on Problem 1860
#include<cstdio>
int s, n, m, i, j, d[222][2], f;
double v, c[222][2], x[111];
int man()
{
	x[s] = v;
	for (i = 1; i < n; i++)
	{
		f = 0;
		for (j = 0; j < 2 * m; j++)
			if (x[d[j][1]] < (x[d[j][0]] - c[j][1])*c[j][0])
				f = 1, x[d[j][1]] = (x[d[j][0]] - c[j][1])*c[j][0];
		if (!f)   return 0;
	}
	for (j = 0; j < 2 * m; j++)
		if (x[d[j][1]] < (x[d[j][0]] - c[j][1])*c[j][0])
			return 1;
	return 0;
}
int main()
{
	scanf("%d%d%d%lf", &n, &m, &s, &v);
	for (i = 0; i < m; i++)
		scanf("%d%d%lf%lf%lf%lf", &d[2 * i][0], &d[2 * i][1], &c[2 * i][0], &c[2 * i][1], &c[2 * i + 1][0], &c[2 * i + 1][1]), d[2 * i + 1][0] = d[2 * i][1], d[2 * i + 1][1] = d[2 * i][0];
	puts(man() ? "YES" : "NO");
}

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