比较简单的算法:但是当点太多需要剪枝,不然很耗时

void Floyd()
{
for(int k=;k<n;++k)
for(int i=;i<n;++i)
for(int j=;j<n;++j)
dj[i][j] = min(dj[i][j],dj[i][k]+dj[k][j]);
}

hdu1869

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define INF (1<<29)
#define N (110) int dj[N][N];
int n,m; void Floyd()
{
for(int k=;k<n;++k)
for(int i=;i<n;++i)
for(int j=;j<n;++j)
dj[i][j] = min(dj[i][j],dj[i][k]+dj[k][j]);
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
for(int i=;i<N;++i)
for(int j=;j<N;++j)
{
if(i != j) dj[i][j] = INF;
else dj[i][j] = ;
}
for(int i=;i<m;++i)
{
int a,b;
scanf("%d%d",&a,&b);
if(a != b) dj[a][b] = dj[b][a] = ;
}
Floyd();
bool flag = true;
for(int i=;i<n;++i)
for(int j=;j<n;++j)
if(dj[i][j] > )
{
flag =false;
break;
}
if(flag) printf("Yes\n");
else printf("No\n");
}
return ;
}

Floyd模板的更多相关文章

  1. Floyd模板(详细操作最基础版)

    #include<cstdio> #include<iostream> using namespace std; #define MAX 500 #define INFE 1& ...

  2. 图论--传递闭包(Floyd模板)

    #include<iostream> #include<cstring> #include<cmath> using namespace std; int dp[1 ...

  3. 图论--最小环--Floyd模板

    #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> ...

  4. 最短路径(Floyd 模板题)

    题目:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2143&cid=1186 #include<stdio.h> #incl ...

  5. poj 1125 谣言传播 Floyd 模板题

    假如有3个点 点1到点2要5分钟 点1到点3要3分钟 那么5分钟的时间可以传遍全图 所以要先找一个点到其他点的最长时间 再从最长的时间里找出最小值 Sample Input 3 // 结点数2 2 4 ...

  6. hdu 1874 畅通工程续(模板题 spfa floyd)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1874 spfa 模板 #include<iostream> #include<stdio ...

  7. poj 2263&& zoj1952 floyd

    Fiber Network Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2725   Accepted: 1252 Des ...

  8. 【HDOJ1217】【Floyd求最长路】

    http://acm.hdu.edu.cn/showproblem.php?pid=1217 Arbitrage Time Limit: 2000/1000 MS (Java/Others)    M ...

  9. TZOJ 3663 最长路径(floyd)

    描述 网络是由很多交换机与网线组成的,网络中的信息可能会在这些网络中不断转发,给定任意两个交换机,我们需要从中找到最快的路径进行转发,我们定义转发过程中所经过的网线条数为两个交换机之间的路径长度.如果 ...

随机推荐

  1. noip模拟赛 密码

    题目描述 YJC把核弹发射密码忘掉了……其实是密码被加密了,但是YJC不会解密.密码由n个数字组成,第i个数字被加密成了如下形式:第k小的满足(2^L)|(P-1)且P为质数的P.YJC希望你能帮他算 ...

  2. FreeMarker与Spring MVC 4集合的HelloWorld示例

    0.整体的项目结构 1.引入POM <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="ht ...

  3. 《WF in 24 Hours》读书笔记 - Hour 2(1) - 第一个Workflow程序

    创建第一个Workflow项目 1. 创建Workflow项目 – 选择Workflow Console Application 2. 添加CodeActivity 3. 打开CodeActivity ...

  4. hdu 1247 Hat’s Words(从给的单词中找hat&#39;s word 并按字典序输出)

    1.在使用mp[key]的时候它会去找键值为key的项,假设没有,他会自己主动加入一个key的项,再把value赋值为对应的初始值(value是int的话赋值为0,string的话赋值为空).所以假设 ...

  5. 在全程Linux環境部署IBM Lotus Domino/Notes 8.5

    架設藍色巨人的協同合作訊息平台 在全程Linux環境部署IBM Lotus Domino/Notes 8.5 珊迪小姐 坊間幾乎所有探討IBM Domino/Notes的中文書籍,皆是以部署在Micr ...

  6. 使用SwipeRefreshLayout和RecyclerView实现仿“简书”下拉刷新和上拉载入很多其它

    一.概述 本篇博客介绍的是怎样使用SwipeRefreshLayout和RecyclerView实现高仿简书Android端的下拉刷新和上拉载入很多其它的效果. 依据效果图能够发现,本案例实现了例如以 ...

  7. sql 分组取每组的前n条或每组的n%(百分之n)的数据

    sql 分组取每组的前n条或每组的n%(百分之n)的数据 sql keyword: SELECT * ,ROW_NUMBER() OVER(partition by b.UserID order by ...

  8. A Taxonomy for Performance

    A Taxonomy for Performance In this section, we introduce some basic performance metrics. These provi ...

  9. 2014年辛星starphp第一节设置入口文件以及App类

    *********************本节目标**************** 1.首先是我们的框架大致布局,我们即将写成的这个框架.它的入口文件统一为star.php.它须要做的一些事,比方载入 ...

  10. UIView convertRect

    CGRect newRect = [self.view.window convertRect:self.blueView.frame fromView:self.redView]; NSLog(@&q ...