POJ3259 Wormholes [Bellmanford determines whether a negative loop exists]

Source: Internet
Author: User

Very simple bellmanford questions, here more detailed: http://blog.csdn.net/lyy289065406/article/details/6645790

Direct code

#include 
 
  #include 
  
   #include 
   
    #include #include 
    
     #include 
     
      using namespace std;const int SIZE=11111;const int MAXLEN=1<<30;struct sss{int s,e,v;}ed[SIZE];int N,M,WH;int dis[SIZE];int ednum;bool Bellman(){for(int i=0;i
      
       dis[ed[j].s]+ed[j].v){flag=true;dis[ed[j].e]=dis[ed[j].s]+ed[j].v;}}if(!flag)break;}for(int j=0;j
       
        dis[ed[j].s]+ed[j].v){return true;}}return false;}int main(){#ifndef ONLINE_JUDGEfreopen("G:/1.txt","r",stdin);freopen("G:/2.txt","w",stdout);#endifint f,u,v,w;cin>>f;while(f--){ednum=0;cin>>N>>M>>WH;for(int i=0;i
        
         >u>>v>>w;ed[ednum].s=u;ed[ednum].e=v;ed[ednum++].v=v;ed[ednum].e=u;ed[ednum].s=v;ed[ednum++].v=w;}for(int i=0;i
         
          >u>>v>>w;ed[ednum].s=u;ed[ednum].e=v;ed[ednum++].v=-w;}if(Bellman())printf("YES\n");elseprintf("NO\n");} return 0;}
         
        
       
      
     
    
   
  
 

 

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.