hdu6026 Deleting Edges(Dijkstra+思路)
https://vjudge.net/problem/HDU-6026
我一直想不明白的是,它的乘法是如何保证n-1条边的。后来画了一张图大概能明白了。

结合最后的乘法二层循环的代码来看,当i=4的时候,j有1和3满足条件,3满足不用说是迪杰斯特拉本身跑出来的,1满足条件,而中间的点2、3也可以有自己本身的路径达到,最后满足共n-1条边。
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int MOD=1e9+;
ll n, dist[], vis[], a[][];
char b[][];
void dijkstra()
{
for(int i = ; i < n; i++){
dist[i] = INF;
}
dist[]=;
for(int i = ; i < n; i++){
ll mini = INF, k=-;
for(int j = ; j < n; j++){
if(!vis[j]&&dist[j]<mini){
mini = dist[j];
k = j;
}
}
vis[k] = ;
for(int j = ; j < n; j++){
if(!vis[j]&&a[k][j]&&dist[j] > dist[k]+a[k][j]){//0是不通
dist[j] = dist[k]+a[k][j];
}
}
}
}
int main()
{
while(cin >> n){
memset(vis, , sizeof(vis));
for(int i = ; i < n; i++){
cin >> b[i];
for(int j = ; j < n; j++){
a[i][j] = b[i][j]-'';
}
}
dijkstra();
/*for(int i = 0; i < n; i++){
cout << dist[i] << " ";
} cout << endl;*/
ll tmp, ans=;
for(int i = ; i < n; i++){
tmp = ;
for(int j = ; j < n; j++){
if(a[j][i]&&dist[i] == dist[j]+a[j][i]){//0是不通
tmp++;
}
}
ans = (ans*tmp)%MOD;
}
cout << ans << endl;
}
return ;
}
hdu6026 Deleting Edges(Dijkstra+思路)的更多相关文章
- HDU6026 Deleting Edges 2017-05-07 19:30 38人阅读 评论(0) 收藏
Deleting Edges Time ...
- 2017中国大学生程序设计竞赛 - 女生专场 Deleting Edges(思维+最短路)
Deleting Edges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 【HDU6026】Deleting Edges
题意 有一个n个节点的无向图,结点编号从0-n-1,每条边的长度时1to9的一个正整数.现在要删除一些边(或者不删),使得到的新图满足下面两个要求. 1.新图是一颗树有n-1条边2.对于每个结点v(0 ...
- HDU 6026 Deleting Edges
最短路. 先建一个只包含最短路的有向无环图,每一个点选择任意一条入边即可生成一个树形图,那么树的种类就等于每个点的入度乘积. #include <bits/stdc++.h> using ...
- POJ 2387 Til the Cows Come Home Dijkstra求最短路径
Til the Cows Come Home Bessie is out in the field and wants to get back to the barn to get as much s ...
- hdu4496 D-City(扭转和支票托收啊 )
主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4496 D-City Problem Description Luxer is a really bad ...
- hdu4496-D-city--逆序并查集
D-City Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Subm ...
- HDU4496 D-City【基础并查集】
Problem Description Luxer is a really bad guy. He destroys everything he met. One day Luxer went to ...
- hdu-4496-D-City
D-City Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Subm ...
随机推荐
- .net core 中的 DependencyInjection - IOC
概要:因为不知道写啥,所以随便找个东西乱说几句,嗯,就这样,就是这个目的. 1.IOC是啥呢? IOC - Inversion of Control,即控制反转的意思,这里要搞明白的就是,它是一种思想 ...
- Codeforces 666E E - Forensic Examination SA + 莫队 + 线段树
E - Forensic Examination 我也不知道为什么这个复杂度能过, 而且跑得还挺快, 数据比较水? 在sa上二分出上下界, 然后莫队 + 线段树维护区间众数. #include< ...
- JAXB在Java 9/10并且使用Tomcat 9的问题
Implementation of JAXB-API has not been found on module path or classpath. JAXB API是java EE 的API,jav ...
- P1052 过河 线性dp 路径压缩
题目描述 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上.由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把独木桥上青蛙可能到达的点看成数 ...
- mybatis相关知识
@param解释为映射mapper.xml中的传参 mybatis中批量新增时用foreach循环,注意其中的collection属性,有list,数组 注意foreach中sql函数的写法,orac ...
- UDF、UDAF、UDTF函数编写
一.UDF函数编写 1.步骤 1.继承UDF类 2.重写evalute方法 .继承GenericUDF .实现initialize.evaluate.getDisplayString方法 2.案例 实 ...
- poj 2502 Subway【Dijkstra】
<题目链接> 题目大意: 某学生从家到学校之间有N(<200)条地铁,这个学生可以在任意站点上下车,无论何时都能赶上地铁,可以从一条地铁的任意一站到另一条地跌的任意一站,学生步行速度 ...
- Git 日常工作中使用的命令记录
前言 这篇文章主要是介绍我在使用Git中的有一些忘记了,但是很重要的命令. 20190424 Git 历史信息 username 和 email 更改 git config alias.chang ...
- CSS-变量
为什么使用 css variables 借用Scrimba上的: easier to get started (no transpiling) have access to the DOM 1.loc ...
- Windows下MySQL绿色版安装配置与使用
Mysql-5.7.11-winx64操作步骤: 一.安装MySQL数据库 1.下载. 下载地址: http://downloads.mysql.com/archives/get/file/mysql ...