hdu5422(BC)

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5422


There are no more than 100 testcases.

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

Then m lines follow. Each line contains two numbers u,v(1u,vn) , 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

只要注意是无向图就OK


#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define ll long long
const double eps = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;

int n,m;
int mat[105][105];

int main ()
{
    int a,b,flag;
    while (scanf ("%d%d",&n,&m)==2)
    {
        flag=0;
        memset(mat, 0, sizeof(mat));
        for (int i=0; i<m; i++)
        {
            scanf ("%d%d",&a,&b);
            if ((a==1&&b==n)||(a==n&&b==1))
                flag=1;
            if (a!=b&&!mat[a][b])
            {
                mat[a][b] = 1;
                mat[b][a] = 1;
            }
        }
        if (!flag)
            printf ("1 1\n");
        else
            printf ("1 %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、付费专栏及课程。

余额充值