zoukankan      html  css  js  c++  java
  • HDU1599杭州旅游

    P2457 - 【HDU1599】杭州旅游

    Description

    杭州有 N 个景区, 景区之间有一些双向的路来连接, 现在 8600 想找一条旅游路线, 这 个路线从 A 点出发并且最后回到 A 点。
    假设经过的路线为 V1,V2,....VK,V1,那么必须满足 K>2,就是说至除了出发点以外至少要经 过 2 个其他不同的景区, 而且不能重复经过同一个景区。 现在 8600 需要你帮他找一条这样 的路线, 并且花费越少越好。

    Input

    第一行是 2 个整数 N 和 M( N <= 800, M <= 600000), 代表景区的个数和道路的条数。
    接下来的 M 行里, 每行包括 3 个整数 a,b,c.代表 a 和 b 之间有一条通路, 并且需要花费 c 元(c <= 10000)。

    Output

    如果能找到这样一条路线的话, 输出花费的最小值。 如果找不到的话, 输出 "It's impossible." (没有双引号)

    Sample Input

    输入样例1:
    3 3
    1 2 1
    2 3 1
    1 3 1

    输入样例2:
    3 3
    1 2 1
    1 2 3
    2 3 1

    Sample Output

    输出样例1:
    3

    输出样例2:
    It's impossible.

    Hint

    【数据范围】
    对于 40%的数据: 2 <= n < 100, m<=10000
    对于 100%的数据: n <= 800, m<=600000

    Source

    最小环

    最小环,用Floyed即可

     1 /* QYP kuai wo dai ma*/
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<iomanip>
     5 #include<cstring>
     6 #include<cstdlib>
     7 #include<cstdio>
     8 #include<queue>
     9 #include<ctime>
    10 #include<cmath>
    11 #include<stack>
    12 #include<map>
    13 #include<set>
    14 #define rep(i,a,b) for(register int i=a;i<=b;i++)
    15 #define ll long long
    16 #define re register
    17 #define inf 1<<29
    18 using namespace std;
    19 const int N=810,M=600010;
    20 int n,m,ans=inf;
    21 int d[N][N],g[N][N];
    22 inline int gi() {
    23     re int res=0;
    24     char ch=getchar();
    25     while(ch<'0'||ch>'9') ch=getchar();
    26     while(ch>='0'&&ch<='9') res=res*10+ch-'0',ch=getchar();
    27     return res;
    28 }
    29 void Floyed() {
    30     rep(k,1,n) {
    31         rep(i,1,k-1)
    32             rep(j,i+1,k-1)
    33               ans=min(ans,d[i][j]+g[i][k]+g[k][j]);
    34         rep(i,1,n)
    35             rep(j,1,n)
    36               d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    37     }
    38 }
    39 int main() {
    40     freopen("zdlcs.in","r",stdin);
    41     freopen("zdlcs.out","w",stdout);
    42     n=gi(),m=gi();
    43     memset(g,127/3,sizeof(g));
    44     rep(i,1,n)
    45         rep(j,1,n)
    46           if(i!=j)
    47                 d[i][j]=inf;
    48     rep(i,1,m){
    49         re int u=gi(),v=gi(),w=gi();
    50         if(g[u][v]<=w) continue;
    51         g[u][v]=g[v][u]=w;
    52         d[u][v]=d[v][u]=w;
    53     }
    54     Floyed();
    55     if(ans==inf) puts("It's impossible.");
    56     else
    57     printf("%d",ans);
    58 }
  • 相关阅读:
    使用C语言来扩展PHP,写PHP扩展dll
    用C语言写PHP扩展 linux
    mysql 建索引删除索引命令
    xhprof安装&&使用
    Burst Windows 2003 VPS安装中文语言包图文教程
    yii框架的缓存
    rsync的配置与应用
    mysql分组排序取前N条记录的最简洁的单条sql !
    linux下php以fastcgi模式运行
    JS收集<2>:图片上传_限制格式、类型、尺寸
  • 原文地址:https://www.cnblogs.com/ypz999/p/6818818.html
Copyright © 2011-2022 走看看