hdu 5422 Rikka with Graph(简单题)

时间:2020-12-02 07:52:29
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 . Now he wants to add exactly an edge which connects two different vertices and minimize the length of the shortest path between vertice  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  testcases. 

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

Then m lines follow. Each line contains two numbers u,v(≤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  and vertice n and the number of the ways of adding this edge.

 
Sample Input
 
 
Sample Output
 
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(n−1)​​。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
#define N 106
int n,m;
int mp[N][N];
int main()
{
while(scanf("%d%d",&n,&m)==){
memset(mp,,sizeof(mp));
for(int i=;i<m;i++){
int u,v;
scanf("%d%d",&u,&v);
mp[u][v]=mp[v][u]=;
}
if(mp[][n]){
printf("1 ");
printf("%d\n",n*(n-)/);
}
else{
printf("1 ");
printf("1\n");
}
}
return ;
}