Floyd模板
比较简单的算法:但是当点太多需要剪枝,不然很耗时
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]);
}
#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模板的更多相关文章
- Floyd模板(详细操作最基础版)
#include<cstdio> #include<iostream> using namespace std; #define MAX 500 #define INFE 1& ...
- 图论--传递闭包(Floyd模板)
#include<iostream> #include<cstring> #include<cmath> using namespace std; int dp[1 ...
- 图论--最小环--Floyd模板
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> ...
- 最短路径(Floyd 模板题)
题目:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2143&cid=1186 #include<stdio.h> #incl ...
- poj 1125 谣言传播 Floyd 模板题
假如有3个点 点1到点2要5分钟 点1到点3要3分钟 那么5分钟的时间可以传遍全图 所以要先找一个点到其他点的最长时间 再从最长的时间里找出最小值 Sample Input 3 // 结点数2 2 4 ...
- hdu 1874 畅通工程续(模板题 spfa floyd)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1874 spfa 模板 #include<iostream> #include<stdio ...
- poj 2263&& zoj1952 floyd
Fiber Network Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2725 Accepted: 1252 Des ...
- 【HDOJ1217】【Floyd求最长路】
http://acm.hdu.edu.cn/showproblem.php?pid=1217 Arbitrage Time Limit: 2000/1000 MS (Java/Others) M ...
- TZOJ 3663 最长路径(floyd)
描述 网络是由很多交换机与网线组成的,网络中的信息可能会在这些网络中不断转发,给定任意两个交换机,我们需要从中找到最快的路径进行转发,我们定义转发过程中所经过的网线条数为两个交换机之间的路径长度.如果 ...
随机推荐
- Codeforces Round #260 (Div. 2) D
D. A Lot of Games time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #219 (Div. 2) D题
D. Counting Rectangles is Fun time limit per test 4 seconds memory limit per test 256 megabytes inpu ...
- 在JQuery中$(document.body)和这个$("body") 这两的区别在哪里?
两种写法代表的是同一个对象 $("body") 是一个选择器,jQuery 会从 DOM 顶端开始搜索,直到找到标签为 body 的元素. 而 $(document.body) 中 ...
- cocos2d-x大版本号3.1系列一
本人博客,欢迎转载:http://blog.csdn.net/dawn_moon 项目忙完了.继续写我的博客.去cocos2d-x的官网看了下,不出所料.又有惊喜啊.3.0经过几个版本号的迭代,最终迎 ...
- 程序员之---C语言细节20(符号和有符号之间转换、两数相加溢出后数值计算)
主要内容:无符号和有符号之间转换.两数相加溢出后数值计算 #include <stdio.h> /* 这个函数存在潜在漏洞 */ float sum_elements(float a[], ...
- [JavaEE] Implement a REST Endpoint
1. Create a rest folder with JAXRSConfiguration.java: package com.pluralsight.bookstore.rest; import ...
- 我的CSDN博客停止更新通告
我的CSDN博客停止更新通告 自从2001年在CSDN发表第一篇博客開始,至今天(2014年6月11日)为止,算起来我己经在CSDN博客上"呆"了13年.共发表251篇原创文章,有 ...
- python编程(基于twisted的client编程)
[ 声明:版权全部,欢迎转载.请勿用于商业用途. 联系信箱:feixiaoxing @163.com] python的twisted比較有意思,既能够做server方面的编程,也能够做client方面 ...
- LeetCode 781. Rabbits in Forest (森林中的兔子)
题目标签:HashMap 题目给了我们一组数字,每一个数字代表着这只兔子说 有多少只一样颜色的兔子. 我们把每一个数字和它出现的次数都存入map.然后遍历map,来判断到底有多少个一样颜色的group ...
- 【Spark】Stage生成和Stage源代码浅析
引入 上一篇文章<DAGScheduler源代码浅析>中,介绍了handleJobSubmitted函数,它作为生成finalStage的重要函数存在.这一篇文章中,我将就DAGSched ...