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.

首先最小距离肯定是1,不可能比1还小。

其次最小距离肯定是1,因为只要连1和n就能达到1。

那么如果一开始1和n没有相连,那么连接1和n能达到1,否则均大于1。

如果1和n一开始就相连,那么随便连两条就OK,C(n, 2) = n*(n-1)/2。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <vector>
#define LL long long using namespace std; int n, m;
bool dis[][]; int input()
{
if (scanf("%d%d", &n, &m) == EOF)
return false;
memset(dis, false, sizeof(dis));
int u, v;
for (int i = ; i < m; ++i)
{
scanf("%d%d", &u, &v);
dis[u][v] = dis[v][u] = true;
}
return true;
} void work()
{
printf("1 ");
if (dis[][n])
printf("%d\n", n*(n-)/);
else
printf("1\n");
} int main()
{
//freopen("test.in", "r", stdin);
while (input())
{
work();
}
return ;
}

ACM学习历程—HDU5422 Rikka with Graph(贪心)的更多相关文章

  1. ACM学习历程—HDU5423 Rikka with Tree(搜索)

    Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...

  2. ACM学习历程——NOJ1113 Game I(贪心 || 线段树)

    Description 尼克发明了这样一个游戏:在一个坐标轴上,有一些圆,这些圆的圆心都在x轴上,现在给定一个x轴上的点,保证该点没有在这些圆内(以及圆上),尼克可以以这个点为圆心做任意大小的圆,他想 ...

  3. ACM学习历程——HDU5202 Rikka with string(dfs,回文字符串)

    Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...

  4. ACM学习历程—CSU 1216 异或最大值(xor && 贪心 && 字典树)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1216 题目大意是给了n个数,然后取出两个数,使得xor值最大. 首先暴力枚举是C(n,  ...

  5. ACM学习历程—HihoCoder1309任务分配(排序 && 贪心)

    http://hihocoder.com/problemset/problem/1309 题目大意是给定n个任务的起始时间,求问最少需要多少台机器. 有一个贪心的策略就是,如果说对于一个任务结束,必然 ...

  6. ACM学习历程—HDU4415 Assassin’s Creed(贪心)

    Problem Description Ezio Auditore is a great master as an assassin. Now he has prowled in the enemie ...

  7. ACM学习历程—FZU 2144 Shooting Game(计算几何 && 贪心 && 排序)

    Description Fat brother and Maze are playing a kind of special (hentai) game in the playground. (May ...

  8. ACM学习历程—HDU 4726 Kia's Calculation( 贪心&&计数排序)

    DescriptionDoctor Ghee is teaching Kia how to calculate the sum of two integers. But Kia is so carel ...

  9. ACM学习历程—HDU4725 The Shortest Path in Nya Graph(SPFA && 优先队列)

    Description This is a very easy problem, your task is just calculate el camino mas corto en un grafi ...

随机推荐

  1. EasyNVR无插件摄像机直播之:摄像机网页低延时无插件直播实现

    背景需求 对于摄像机直播,客户反馈的最多就是实现web直播.摆脱插件,可以自定义集成等问题, 对于熟悉EasyNVR已经完美的解决了这些问题.然而对于web播放也存在一些问题,通常我们web播放RTM ...

  2. php数据类型的true和false

  3. Asp.Net 5 Web Hook

    首先,然我们来看一下WebHooks是什么.WebHooks是一个协议.它们是HTTP回调技术.并且它们是"用户定义的HTTP回调".你和 (或) 您的应用程序在有什么事情发生时会 ...

  4. Android系统移植与调试之------->如何修改Android设备添加重启、飞行模式、静音模式等功能(二)

    今天要说的是为Android设备添加重启.飞行模式.静音模式按钮,客户需求中需要添加这项功能,在长按电源键弹出的菜单中没有这些选项,谨以此文记录自己添加这个功能的过程. 首先找到长按电源键弹出的对话框 ...

  5. Linux中源码包安装

    1.准备环境 a.因为是编译安装,所以需要安装gcc编译器 b.下载源码包 2.注意事项 a.源代码保存位置 /usr/local/src/ b.软件安装位置 /usr/local/ c.如何确定安装 ...

  6. android在activity中去掉标题栏

    package com.goodness.goodness; import android.support.v7.app.AppCompatActivity; import android.os.Bu ...

  7. 忘记apple id如何更新应用?

    最近ytkah的app有很多更新提示,之前注册的apple id好久没登录了,突然提示说登录需要验证安全问题,哪还记得噢,最要命的是邮箱收到的加密邮件也需要验证.重新注册一个吧,这次要注意保存相关信息 ...

  8. nginx-gridfs的安装

    mongodb中gridfs适合存放视频和高清图片等等超大文件(小的文件建议不要存在mongodb中): 下面是在centos下配置nginx来訪问mongodb中的mp4文件: 1:安装nginx- ...

  9. 【leetcode刷题笔记】Divide Two Integers

    Divide two integers without using multiplication, division and mod operator. 题解:要求不用乘除和取模运算实现两个数的除法. ...

  10. htmlParser的使用-链接

    基于htmlparser实现网页内容解析:http://www.cnblogs.com/coding-hundredOfYears/archive/2012/12/15/2819217.html ht ...