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

我一直RE,求解决,在别的OJ上都过了,希望大神解释一下

Posted by 0702 at 2015-10-16 19:44:03
我用的是spfa,虚拟节点0向从1时刻开始工作的牛建权值为1的边,最后spfa,输出结束工作时刻为T的点最短路的最小值。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
struct u
{
	int d;
	int a;
	int b;
}cdr[25010];
struct uu
{
	int b;
	int x;
}c[5000000];
bool b[25010],by[25010];
int T,n,l;
queue<int>q;
int h[25010];
int pr=0x7fffffff;
int z[25010];
inline void gj(int a,int b)
{
	c[++l].b=b;
	c[l].x=h[a];
	h[a]=l;
}
inline bool g(const u & aa,const u & bb)
{
	return aa.a<bb.a;
}
int main()
{
	scanf("%d%d",&n,&T);
	for(int i=1;i<=n;i++)
	{
		z[i]=0x3fffffff;
		cdr[i].d=i;
		scanf("%d%d",&cdr[i].a,&cdr[i].b);
		if(cdr[i].a==1)
			gj(0,i);
		if(cdr[i].b==T)
		    by[i]=1;
	}
	sort(cdr+1,cdr+1+n,g);
	for(int i=1;i<=n;i++)
	    for(int y=i+1;y<=n&&cdr[y].a<=cdr[i].b+1;y++)
	        gj(cdr[i].d,cdr[y].d);
	b[0]=1;
	q.push(0);
	while(!q.empty())
	{
		int k=q.front();
		q.pop();
		b[k]=0;
		if(z[k]>pr)
		    continue;
		for(int i=h[k];i;i=c[i].x)
		{
			int u=c[i].b;
			if(z[u]>z[k]+1)
			{
				z[u]=z[k]+1;
				if(!b[u])
				{
					b[u]=1;
					q.push(u);
				}
				if(by[u]&&z[u]<pr)
				{
					pr=z[u];
				}
			}
		}
	}
	if(pr>n)
	    pr=-1;
	printf("%d",pr);
	/*getchar();
	getchar();*/
}

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