• 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.

  • 相关阅读:
    容器字段FieldContainer
    时间选择框
    Java 异常处理的优劣
    RSA 公钥加密算法
    Java 添加播放MIDI音乐
    Java 内存查看与分析
    总结 Eclipse 编程常用的快捷键
    Java 基础【03】序列化和反序列化
    找出给定字符串中出现最多的字符和次数
    Javascript 限制文本字节数
  • 原文地址:https://www.cnblogs.com/waterfalleagle/p/1603031.html
Copyright © 2020-2023  润新知