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)
描述 网络是由很多交换机与网线组成的,网络中的信息可能会在这些网络中不断转发,给定任意两个交换机,我们需要从中找到最快的路径进行转发,我们定义转发过程中所经过的网线条数为两个交换机之间的路径长度.如果 ...
随机推荐
- bzoj4518征途 斜率优化
征途这是一道十分经典的斜率优化 我们可以从题目中的方差来想,也就很容易的到这个式子 \[ans=m^2*\frac{\sum_{i=1}^{m}{(x_i-{\overline{x}})^2}}{m} ...
- PLSQL 下载地址 Spring jar包
PLSQL https://www.allroundautomations.com/ instantclient http://www.oracle.com/technetwork/topic ...
- - > 并查集+路径压缩(详解)(第一节)
先举一个友爱的例子解释一下并查集: 话说江湖上散落着各式各样的大侠,有上千个之多. 他们没有什么正当职业,整天背着剑在外面走来走去,碰到和自己不是一路人的,就免不了要打一架.但大侠们有一个优点就是讲义 ...
- vue2的简单时间选择组件
github: https://github.com/longfei59418888/vui (记得给一个 start,以后有一起讨论,各种好组件) demo : http://60.205.2 ...
- How to Use DHCP Relay over LAN? - DrayTek Corp
Assuming Vigor2960 has two LAN networks. Network Administrator wants that, when the internal DHCP is ...
- 使用jcaptcha插件生成验证码
1.从官网http://jcaptcha.sourceforge.net/下载插件.将对应jar包导入到lib文件夹下 2.创建一个CaptchaServiceSingleton类用来获取jcaptc ...
- leetcode_Product of Array Except Self
描写叙述: Given an array of n integers where n > 1, nums, return an array output such that output[i] ...
- LeetCode 171. Excel Sheet Column Number (Excel 表格列数字)
Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, retur ...
- elasticsearch 布尔过滤器 游标查询 Scroll
组合过滤器 | Elasticsearch: 权威指南 | Elastic https://www.elastic.co/guide/cn/elasticsearch/guide/current/co ...
- visual studio推荐的插件
https://marketplace.visualstudio.com/items?itemName=EricLebetsamer.BootstrapSnippetPack https://mark ...