【HDU】2544 最短路

水水水水水水

复习最短路

SPFA:

#include 
#include 
#define C (c=nc())
using namespace std;

struct wjnsb 
{
	int s,t,val;
}e[10005];
int m,n;
int dis[105];

inline char nc(void)
{
	static char ch[100010],*p1=ch,*p2=ch;
	return p1==p2&&(p2=(p1=ch)+fread(ch,1,100010,stdin),p1==p2)?EOF:*p1++;
}

inline void read(int &n)
{
	static char c;int f=1;n=0;C;
	while (c<'0'||c>'9') c=='-'?f=-1,C:C;
	while (c>='0'&&c<='9') n=(n<<3)+(n<<1)+c-48,C;
	return (void)(n*=f);
}

int main(void)
{
	while (1)
	{
		read(n),read(m);
		if (n==0&&m==0) return 0;
		memset(dis,0x3f,sizeof(dis));
		dis[1]=0;
		register int i,j;
		for (i=1;i<=2*m;i+=2) read(e[i].s),read(e[i].t),read(e[i].val),e[i+1].val=e[i].val,e[i+1].s=e[i].t,e[i+1].t=e[i].s;
		for (i=1;i<=n;++i)
		{
			for (j=1;j<=2*m;++j)
			{
				if (dis[e[j].s]+e[j].val


你可能感兴趣的:(HDU,裸题练手感)