BestCoder Round #53 (div.2) 1001 Rikka with Graph

Rikka with Graph

Accepts: 353
Submissions: 1174
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
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 nnn vertices and mmm 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 nnn. 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)n,m(2 \leq n \leq 100, 0 \leq m \leq 100)n,m(2n100,0m100).

Then mmm lines follow. Each line contains two numbers u,v(1≤u,v≤n)u,v(1 \leq u,v \leq n)u,v(1u,vn) , which means there is an edge between uuu and vvv. 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 nnn 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.

分析:最短路肯定都是1,如果1和n有边,那么随便从n个节点中找两个连接就可以啊,如果无边,那么连接1-n

#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<string.h>
#include<set>
using namespace std;
int main()
{
    int n,m,u,v;
    while(cin>>n>>m){
        bool flag=0;
        for(int i=0;i<m;i++){
            cin>>u>>v;
            if((u==1&&v==n)||(u==n&&v==1))flag=1;
        }
        if(flag)cout<<"1 "<<n*(n-1)/2<<endl;
        else cout<<"1 1"<<endl;
    }
    return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值