HDU6026 Deleting Edges 2017-05-07 19:30 38人阅读 评论(0) 收藏
Deleting Edges
Time Limit: 2000/1000 MS (Java/Others) Memory
Limit: 131072/131072 K (Java/Others)
Total Submission(s): 18 Accepted Submission(s): 9
There is a bi-directional graph with n nodes,
labeled from 0 to n−1.
Every edge has its length, which is a positive integer ranged from 1 to 9.
Now, Little Q wants to delete some edges (or delete nothing) in the graph to get a new graph, which satisfies the following requirements:
(1) The new graph is a tree with n−1 edges.
(2) For every vertice v(0<v<n),
the distance between 0 and v on
the tree is equal to the length of shortest path from 0 to v in
the original graph.
Little Q wonders the number of ways to delete edges to get such a satisfied graph. If there exists an edge between two nodes i and j,
while in another graph there isn't such edge, then we regard the two graphs different.
Since the answer may be very large, please print the answer modulo 109+7.
In each test case, the first line contains an integer n(1≤n≤50),
denoting the number of nodes in the graph.
In the following n lines,
every line contains a string with n characters.
These strings describes the adjacency matrix of the graph. Suppose the j-th
number of the i-th
line is c(0≤c≤9),
if c is
a positive integer, there is an edge between i and j with
length of c,
if c=0,
then there isn't any edge between i and j.
The input data ensure that the i-th
number of the i-th
line is always 0, and the j-th
number of the i-th
line is always equal to the i-th
number of the j-th
line.
2
01
10
4
0123
1012
2101
3210
1
6
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <functional> using namespace std; #define LL long long
const int INF=0x3f3f3f3f;
const int mod=1e9+7; int n,m;
int mp[55][55];
int dis[55];
int vis[55];
LL cnt[55];
struct node
{
int id,val;
friend bool operator<(node a,node b)
{
return a.val>b.val;
}
}; void djstl(int o)
{
memset(dis,INF,sizeof dis);
memset(vis,0,sizeof vis);
memset(cnt,0,sizeof cnt);
node f,d;
f.id=o,f.val=0;
priority_queue<node>q;
q.push(f);
vis[o]=cnt[o]=1,dis[o]=0;
while(!q.empty())
{
f=q.top();
q.pop();
vis[f.id]=1;
for(int i=0; i<n; i++)
{
if(!vis[i]&&f.val+mp[f.id][i]<dis[i])
{
dis[i]=f.val+mp[f.id][i];
cnt[i]=1;
d.id=i;
d.val=dis[i];
q.push(d);
}
else if(!vis[i]&&f.val+mp[f.id][i]==dis[i])
{
cnt[i]++;
}
}
}
} int main()
{
char s[55];
while(~scanf("%d",&n))
{
memset(mp,INF,sizeof mp);
for(int i=0; i<n; i++)
{
scanf("%s",&s);
for(int j=0; j<n; j++)
if(s[j]!='0')
mp[i][j]=s[j]-'0';
} djstl(0);
LL ans=1;
for(int i=0; i<n; i++)
{
ans*=cnt[i];
ans%=mod;
}
printf("%d\n",ans);
}
return 0;
}
HDU6026 Deleting Edges 2017-05-07 19:30 38人阅读 评论(0) 收藏的更多相关文章
- ZOJ2208 To and Fro 2017-04-16 19:30 45人阅读 评论(0) 收藏
To and Fro Time Limit: 2 Seconds Memory Limit: 65536 KB Mo and Larry have devised a way of encr ...
- POJ3320 Jessica's Reading Problem 2017-05-25 19:55 38人阅读 评论(0) 收藏
Jessica's Reading Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12346 Accep ...
- HDU6023 Automatic Judge 2017-05-07 18:30 73人阅读 评论(0) 收藏
Automatic Judge Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- HDU6029 Happy Necklace 2017-05-07 19:11 45人阅读 评论(0) 收藏
Happy Necklace Time Limit: ...
- HDU6029 Graph Theory 2017-05-07 19:04 40人阅读 评论(0) 收藏
Graph Theory Time Limit: 2000/1000 M ...
- HDU6027 Easy Summation 2017-05-07 19:02 23人阅读 评论(0) 收藏
Easy Summation Time Limit: 2000/1000 MS ...
- Network Saboteur 分类: 搜索 POJ 2015-08-09 19:48 7人阅读 评论(0) 收藏
Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10147 Accepted: 4849 Des ...
- 滑雪 分类: POJ 2015-07-23 19:48 9人阅读 评论(0) 收藏
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 83276 Accepted: 31159 Description Mich ...
- 第十二届浙江省大学生程序设计大赛-Lunch Time 分类: 比赛 2015-06-26 14:30 5人阅读 评论(0) 收藏
Lunch Time Time Limit: 2 Seconds Memory Limit: 65536 KB The 999th Zhejiang Provincial Collegiate Pro ...
随机推荐
- Delphi 创建一个url网址快捷方式代码
procedure CreateURLShortcut(const ShortcutFile, URL: string); var F: TextFile; // text file begin {$ ...
- 常用类一一字符串相关类一一StringBuilder,StringBuffer。
package cn.bjsxt.stringbuilder; /** * String 不可变字符序列 * StringBuilder StringBuffer都是是可变字符序列 * 区别在于Str ...
- HTML CSS + DIV实现整体布局 part1
HTML CSS + DIV实现整体布局 1.技术目标: 开发符合W3C标准的Web页面 理解盒子模型 实现DIV+CSS整体布局 2.什么是W3C标准? W3C:World Wide Web Con ...
- bash: ifconfig: command not found 问题解决
ifconfig使用出现问题了?竟然提示找不到~~于是百度~~ [flymouse@localhost /]$ ifconfig 提示:“bash: ifconfig: command not fou ...
- DESeq2包
1)简介: DESeq2-package: for differential analysis of count data(对count data 做差异分析) 2)安装 if("DESeq ...
- moco入门
前提:moco是什么?有什么用 Moco是针对HTTP集成而生的,不过,现在也有人把它用在其它需要一个模拟服务器的场景中.比如,在移动开发中,有人开发一个移动应用,需要有一个远端服务,但在开发时,这个 ...
- in文件注意事项及详细解释
lammps做分子动力学模拟时,需要一个输入文件(input script),也就是in文件,以及关于体系的原子坐标之类的信息文件(data file)和势文件(potential file).lam ...
- MyEclipse/eclipse 添加作者、注释、版本、时间等
preferences>>java>>code style>>code templates>>comments>>找到相应的编辑即可
- 【校招面试 之 C/C++】第16题 C++ new和delete的实现原理
1.new new操作针对数据类型的处理,分为两种情况: (1)简单数据类型(包括基本数据类型和不需要构造函数的类型) 代码实例: int* p = new int; 汇编码如下: int* p = ...
- python之信号量【Semaphore】
# 互斥锁同时只允许一个线程更改数据,而Semaphore是同时允许一定数量的线程更改数据,比如 # 一个厕所有3个坑,那么最多只允许3个人上厕所,后面的人只能等里面有人出来了才能再进去 import ...