Bellman_ford Shortest circuit

Source: Internet
Author: User

1#include <cstdio>2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cmath>6#include <queue>7 #defineINF 0x3f3f3f3f8 Const intMAXN = $;9 intN, M, PRE[MAXN], EDGE[MAXN * maxn][3];Ten intDIST[MAXN]; One BOOLRelaxintUintVintc) { A     if(Dist[v] > Dist[u] +c) { -DIST[V] = Dist[u] + C; PRE[V] =u; -         return true; the     } -     return  false; - } - intBellmanintS) { +     intI, J; -      for(i =0; I < n; i + +){ +Dist[i] =inf; APre[i] =-1; at     } -Dist[s] =0; -     BOOLFlag; -      for(i =1; i < n; i + +){ -Flag =false; -          for(j =0; J < M; J + +) in             if(Relax (edge[j][0], edge[j][1], edge[j][2]) flag =true; -         if(!flag) Break; to     } +      for(j =0; J < M; J + +) -         if(Relax (edge[j][0], edge[j][1], edge[j][2]))return false; the     return true; *}

Bellman_ford Shortest circuit

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.