zoukankan      html  css  js  c++  java
  • vj p1046 观光旅游 题解

    原体叙述

    此题简单最小环,用来练练手

    最小环如下:

    const maxnum=16843009;
    var
            n,m,r:longint;
            map,f:array[0..100,0..100]of longint;
    procedure main;
    var
            i,a,k,j,b,c:longint;
    begin
            readln(n,m);
            fillchar(map,sizeof(map),1);
            for i:=1 to m do
                    begin
                            readln(a,b,c);
                            map[a,b]:=c;
                            map[b,a]:=c;
                    end;
            for i:=1 to n do map[i,i]:=0;
            f:=map;
            r:=maxnum;
            for k:=1 to n do
                begin
                    for i:=1 to k-1 do
                        for j:=i+1 to k-1 do
                            if f[i,j]+map[j,k]+map[k,i]<r then
                                r:=f[i,j]+map[j,k]+map[k,i];
                    for i:=1 to n do
                        for j:=1 to n do
                            if f[i,j]>f[i,k]+f[k,j] then
                                f[i,j]:=f[i,k]+f[k,j];
                end;
            if r<maxnum then writeln(r) else writeln('No solution.');
    end;
    begin
           
            while not(eof) do main;
    end.

  • 相关阅读:
    [LeetCode] Convert Sorted Array to Binary Search Tree
    [LeetCode] Diameter of Binary Tree
    [LeetCode] Student Attendance Record I
    [LeetCode] Reverse String II
    [LeetCode] Missing Number
    [LeetCode] Intersection of Two Arrays II
    [LeetCode] Base 7
    Ubuntu中firefox设置成中文
    Linux中的查找命令find
    Ubuntu14.04安装配置Chrome浏览器
  • 原文地址:https://www.cnblogs.com/waterfalleagle/p/1603031.html
Copyright © 2011-2022 走看看