hdu5422#53-div2-1Rikka with Graph

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 nn vertices and mm 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 nn. 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 \leq n \leq 100, 0 \leq m \leq 100)n,m(2n100,0m100).

Then mm lines follow. Each line contains two numbers u,v(1 \leq u,v \leq n)u,v(1u,vn) , which means there is an edge between uu and vv. 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 nn 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.

当我理解明白题意时,内心几乎是崩溃的==

勇太有一张nn个点mm条边的无向图,每一条边的长度都是1。现在他想再在这张图上连上一条连接两个不同顶点边,使得1号点到nn号点的最短路尽可能的短。现在他想要知道最短路最短是多少,以及再保证最短路最短的情况下,他有多少种连边的方案。
题解:看了提问才明白==最后的最短路一定是1,要是原来1和n没连上,只能连他俩 否则N个点中任意找两个连上即可 亏我还费劲找最短路模板和组合数求法==
#include <iostream>
#include<cstdio>
#include<cstring>
#define MaxN 110
#define MaxInt 65535
using namespace std;
int n,m;
bool A[102][102];
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        for(int i=1; i<=n; i++)
        {
            for(int j=i+1; j<=n; j++)
                A[i][j]=A[j][i]=0;
        }
        int a,b;
        while(m--)
        {
            scanf("%d%d",&a,&b);
            A[b][a]=A[a][b]=1;
        }
        printf("1 ");
       /* start=1;nd=n;
        int tmp=dijkstra(),tmp1;
        int mark=0;
        int num[10000];
        for(int i=1;i<n;i++)
        {
            for(int j=i+1;j<=n;j++)
            {
                if(A[i][j]!=MAXINT)
                {
                    A[i][j]=A[j][i]=1;
                    tmp1=dijkstra();
                    if(tmp1<tmp)       num[++mark]=1,tmp=tmp1;
                    else if(tmp1==tmp) num[mark]++;
                    A[i][j]=A[j][i]=MAXINT;
                }
            }
        }*/

        if(!A[1][n]) printf("1\n");
        else printf("%d\n",n*(n-1)/2);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值