POJ 3268 (SPFA)

Source: Internet
Author: User

http://poj.org/problem?id=3268

For this problem, I would like to say is the day of the dog, what ghost, the definition of a number of different order, one on the tle, one on a, also 16MS.

Sense of life are running into the collapse, sure enough, the topic will always see ghosts!!!!!!

The heart is tired, do not want to write this question.

1#include <stdio.h>2#include <string.h>3#include <queue>4#include <iostream>5 #defineINF 0x3f6 #defineMAX1 10107 #defineMax2 1000108 9 using namespacestd;Ten intm,n,x; One intMark[max1]; A intNext[max1]; - intU[MAX2]; Swap the 13 and 14 lines, and you'll get the results completely different.  - intV[MAX2]; the intW[MAX2]; - intA[MAX2],B[MAX2],C[MAX2]; - intDist[max1]; - intAns[max1]; + BOOLVis[max1]; -  +  AQueue <int>s; at voidInit () - { -memset (Vis,false,sizeof(Vis)); -      while( !s.empty ()) S.pop (); -memset (Dist,inf,sizeof(Dist)); -dist[x]=0; in      for(intI=1; i<=n;i++) -mark[i]=-1; to } +  - voidSPFA () the { * s.push (x); $vis[x] =true ;Panax Notoginseng      while( !s.empty ()) -     { the         intTMP =S.front (); + S.pop (); Avis[tmp] =false; the          for(inti = mark[TMP]; I! =-1; i =next[i]) +         { -             if(dist[tmp] + w[I] <dist[v[i]]) $             { $dist[v[i]] = dist[TMP] +w[i]; -                 if( !vis[v[i]]) -                 { the S.push (v[i]); -vis[v[I] =true;Wuyi                 } the             } -         } Wu     } -      for(inti =1; I <= N; i++ ) Aboutans[i] + =dist[i]; $ } -  - intMain () - { A  //freopen ("In.txt", "R", stdin); +      while(~SCANF ("%d%d%d",&n,&m,&x)) the     { -memset (ans,0,sizeof(ans)); $ init (); the          for(inti =1; I <= m; i++ ) the         { thescanf"%d%d%d", &a[i],&b[i],&c[i]); theu[I] =a[i]; -v[I] =b[i]; inw[I] =c[i]; thenext[I] =Mark [u[i]]; themark[u[I] =i; About         } the SPFA (); the init (); the          for(inti =1; I <= m; i++ ) +         { -v[I] =a[i]; theu[I] =b[i];Bayiw[I] =c[i]; thenext[I] =mark[u[i]; themark[u[I] =i; -         } - SPFA (); the         intMax = ans[1]; the          for(inti =2; I <= N; i++ ) the             if(ans[i] > Max) Max =ans[i]; theprintf"%d\n", Max); -     } the     return 0; the}

POJ 3268 (SPFA)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.