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)
描述 网络是由很多交换机与网线组成的,网络中的信息可能会在这些网络中不断转发,给定任意两个交换机,我们需要从中找到最快的路径进行转发,我们定义转发过程中所经过的网线条数为两个交换机之间的路径长度.如果 ...
随机推荐
- java 源码分析1 -String
1. String的本质是一个 char数组,实现了CharSequence 接口, /** The value is used for character storage. */ private f ...
- graylog 市场
https://marketplace.graylog.org/addons/246dc332-7da7-4016-b2f9-b00f722a8e79
- idea常用快捷键汇总
自动导入或补全 Ctrl+空格,代码提示自动提示待输入项 Ctrl+Shift+空格,自动补全代码语句 Ctrl+Alt+空格,类名自动完成 Ctrl+Shift + Enter,语句完成(完成当前语 ...
- 22、Java并发性和多线程-Java中的读/写锁
以下内容转自http://ifeve.com/read-write-locks/: 相比Java中的锁(Locks in Java)里Lock实现,读写锁更复杂一些.假设你的程序中涉及到对一些共享资源 ...
- Jupyter Notebook: 解决build docker-stacks时conda太慢的问题
当想使用docker安装Jupyter Notebook时,有一个很好的项目是docker-stacks(https://github.com/jupyter/docker-stacks/tree/m ...
- 类似于SVN的文档内容差异对比工具winmerge
原文:http://www.jianshu.com/p/99282a4f3870 https://sourceforge.net/projects/winmerge/?source=typ_redir ...
- 1. MaxCounters 计数器 Calculate the values of counters after applying all alternating operations: increase counter by 1; set value of all counters to current maximum.
package com.code; import java.util.Arrays; public class Test04_4 { public static int[] solution(int ...
- hp 1810-24g switch reset
Specific steps to execute the factory default reset on the switch are: 1. Using a small, thin tool w ...
- ZOJ 3201
id=15737" target="_blank">Tree of Tree Time Limit: 1000MS Memory Limit: 32768KB ...
- Android获取全部存储卡挂载路径
近期因项目需求.须要在存储卡查找文件,经測试发现部分手机挂载路径查找不到,这里分享一个有效的方法. /** * 获取全部存储卡挂载路径 * @return */ public static List& ...