码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5422 Rikka with Graph(简单题)

时间:2015-08-29 23:16:15      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:

Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:

Yuta has a non-direct graph with n vertices and m edges. The length of each edge is 1. Now he wants to add exactly an edge which connects two different vertices and minimize the length of the shortest path between vertice 1 and vertice n. Now he wants to know the minimal length of the shortest path and the number of the ways of adding this edge.

It is too difficult for Rikka. Can you help her?

 

 

 

Input
There are no more than 100 testcases. 

For each testcase, the first line contains two numbers n,m(2≤n≤100,0≤m≤100).

Then m lines follow. Each line contains two numbers u,v(1≤u,v≤n) , which means there is an edge between u and v. There may be multiedges and self loops.

 


 

 

Output
For each testcase, print a single line contains two numbers: The length of the shortest path between vertice 1 and vertice n and the number of the ways of adding this edge.

 


 

 

Sample Input
 
 
2 1 
1 2

 

 

Sample Output
1 1

 


Hint
You can only add an edge between 1 and 2.
 

 

Source
 

如果连上1-nnn的边,最短距离就是1。所以所有情况下最短距离都是1。

考虑方案数,如果本来没有1-nnn的边,那么只能连1-nnn,方案数为1。否则怎么连都可以,方案数是n(n−1)2\frac{n(n-1)}{2}?2??n(n1)??

技术分享
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<vector>
 5 #include<set>
 6 #include<map>
 7 #include<queue>
 8 #include<algorithm>
 9 using namespace std;
10 #define N 106
11 int n,m;
12 int mp[N][N];
13 int main()
14 {
15     while(scanf("%d%d",&n,&m)==2){
16             memset(mp,0,sizeof(mp));
17         for(int i=0;i<m;i++){
18             int u,v;
19             scanf("%d%d",&u,&v);
20             mp[u][v]=mp[v][u]=1;
21         }
22         if(mp[1][n]){
23             printf("1 ");
24             printf("%d\n",n*(n-1)/2);
25         }
26         else{
27             printf("1 ");
28             printf("1\n");
29         }
30     }
31     return 0;
32 }
View Code

 

hdu 5422 Rikka with Graph(简单题)

标签:

原文地址:http://www.cnblogs.com/UniqueColor/p/4769945.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!