HDU6026-Deleting Edges
来源:互联网 发布:java rmi 框架 编辑:程序博客网 时间:2024/06/06 03:47
Deleting Edges
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0
Problem Description
Little Q is crazy about graph theory, and now he creates a game about graphs and trees.
There is a bi-directional graph withn 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 withn−1 edges.
(2) For every verticev(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 nodesi 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 modulo109+7 .
There is a bi-directional graph with
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
(2) For every vertice
Little Q wonders the number of ways to delete edges to get such a satisfied graph. If there exists an edge between two nodes
Since the answer may be very large, please print the answer modulo
Input
The input contains several test cases, no more than 10 test cases.
In each test case, the first line contains an integern(1≤n≤50) , denoting the number of nodes in the graph.
In the followingn 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 thei -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.
In each test case, the first line contains an integer
In the following
The input data ensure that the
Output
For each test case, print a single line containing a single integer, denoting the answer modulo 109+7 .
Sample Input
2011040123101221013210
Sample Output
16
题意:有n个点,告诉你两两之间的边,让你去掉一些边,使得0号节点到其他节点都是最短路,问有多少种这样的图
解题思路:最短路,先建一个只包含最短路的有向无环图,每一个点选择任意一条入边即可生成一个树形图,那么树的种类就等于每个点的入度乘积
#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 longconst int INF=0x3f3f3f3f;#define mod 1000000007int n,s[60],nt[5009],e[5009],l[5009],visit[60],dis[60];LL a[60];char ch[60][60];struct node{ int id,l; friend bool operator <(node a,node b) { return a.l>b.l; }};void Dijkstra(){ memset(visit,0,sizeof visit); memset(dis,INF,sizeof dis); priority_queue<node>q; node pre,nt1; pre.id=0,pre.l=0,a[0]=1; dis[0]=0; q.push(pre); while(!q.empty()) { pre=q.top(); q.pop(); visit[pre.id]=1; for(int i=s[pre.id];~i;i=nt[i]) { int ee=e[i]; if(visit[ee]) continue; if(dis[ee]>pre.l+l[i]) { a[ee]=1; dis[ee]=pre.l+l[i]; nt1.id=ee; nt1.l=dis[ee]; q.push(nt1); } else if(dis[ee]==pre.l+l[i]) a[ee]++; } } LL ans=1; for(int i=0;i<n;i++) { ans*=a[i]; ans%=mod; } printf("%lld\n",ans);}int main(){ while(~scanf("%d",&n)) { int cnt=0; memset(s,-1,sizeof s); for(int i=0;i<n;i++) { scanf("%s",ch[i]); for(int j=0;j<n;j++) { if(ch[i][j]!='0') nt[cnt]=s[i],s[i]=cnt,e[cnt]=j,l[cnt++]=ch[i][j]-'0'; } } Dijkstra(); } return 0;}
0 0
- HDU6026-Deleting Edges
- HDU6026 Deleting Edges
- HDU6026 Deleting Edges(Dijkstra)
- 最短路径-Deleting Edges-hdu6026
- HDU6026 Deleting Edges (最短路树计数)
- HDU 6026 Deleting Edges
- hdu 6026 Deleting Edges
- HDU 6026 Deleting Edges【图论】
- hdu 6026 Deleting Edges(最短路)
- Hdu 6026 Deleting Edges【思维+最短路】
- 2017 CCPC-WFinal&&HDOJ6026 Deleting Edges
- 2017CCPC女生赛 hdu 6026 Deleting Edges
- HDU 6026 Deleting Edges【最短路】【思维题】
- HDU6026(最短路)
- Deleting Logs
- Deleting Clients
- ZOJ_3643Keep Deleting
- POJ3712Edges and More Edges
- 反序列化对象(控制台应用程序,二进制序列化)
- UA:User-agent是什么?
- 完全二叉树的判断
- 归并排序
- 线程池类ThreadPoolExecutor介绍
- HDU6026-Deleting Edges
- JAVA 多态中的成员访问特点
- {递归}埃及分数
- 有关eclipse中的jar包的说明
- AS版本与 gradle不兼容: This version of Android Studio is incompatible with the Gradle Plugin used.
- 树莓派瞎折腾[1]-实现简单的命令行音乐播放器
- C# 将txt文件的数据库元组导入数据库,代码实现
- 补作业 实验5第4
- c语言习题(2)--键值对,字符串反转