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+思路)的更多相关文章

  1. HDU6026 Deleting Edges 2017-05-07 19:30 38人阅读 评论(0) 收藏

    Deleting Edges                                                                                  Time ...

  2. 2017中国大学生程序设计竞赛 - 女生专场 Deleting Edges(思维+最短路)

    Deleting Edges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  3. 【HDU6026】Deleting Edges

    题意 有一个n个节点的无向图,结点编号从0-n-1,每条边的长度时1to9的一个正整数.现在要删除一些边(或者不删),使得到的新图满足下面两个要求. 1.新图是一颗树有n-1条边2.对于每个结点v(0 ...

  4. HDU 6026 Deleting Edges

    最短路. 先建一个只包含最短路的有向无环图,每一个点选择任意一条入边即可生成一个树形图,那么树的种类就等于每个点的入度乘积. #include <bits/stdc++.h> using ...

  5. 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 ...

  6. hdu4496 D-City(扭转和支票托收啊 )

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4496 D-City Problem Description Luxer is a really bad ...

  7. hdu4496-D-city--逆序并查集

    D-City Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Subm ...

  8. HDU4496 D-City【基础并查集】

    Problem Description Luxer is a really bad guy. He destroys everything he met.  One day Luxer went to ...

  9. hdu-4496-D-City

    D-City Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Subm ...

随机推荐

  1. 【NPM】常见问题解决

    问题列表 问题一:npm install 执行报错 npm ERR! Unexpected end of JSON input while parsing near '...ependencies&q ...

  2. 【Android】Android模拟器快速root

    启动Android模拟器,开始-运行-输入cmd,运行命令行 adb shell mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system ...

  3. Vue小问题汇总

    1.element-UI等组件更改默认样式: >>> https://vue-loader-v14.vuejs.org/zh-cn/features/scoped-css.html ...

  4. 【转】 诡异的ORA-02289: sequence does not exist

    原文地址:http://blog.itpub.net/20801486/viewspace-695651/ 今天被开发人员告知在应用用户下无法查询自己创建的sequence的nextval值.当执行s ...

  5. js中时间大小的比较

    今天在前台做到一个需要比较两个日期大小的地方,乍一看,发现一个比较奇怪地地方: var t1 = new Date(2018,1,1), t2 = new Date(2018,1,1); consol ...

  6. mysql配置完半同步复制之后报错[ERROR] The server quit without updating PID file

    修改配置,MySQL启动报:[ERROR] The server quit without updating PID file [root@localhost mysql]# /etc/init.d/ ...

  7. Codeforces 746F Music in Car

    Music in Car 用两个Set维护一下尺取的过程. #include<bits/stdc++.h> #define LL long long #define fi first #d ...

  8. jquery模拟form表单提交并新打开页面

    /** * form表单提交本页面打开 * @param url * @param params */ function postCurrent(url,params){ var form = $(& ...

  9. 【JavaScript】对象

    No1: typeof操作符获取对象的类型 null的类型是object,Array的类型也是object,如果我们用typeof将无法区分出null.Array和通常意义上的object——{}. ...

  10. python 配置导入方式

    许多连接,如 from setting import redis_config pool= redis.ConnectionPool(**redis_config) r=redis.Redis(con ...