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. github入门基础之上传本地文件以及安装github客户端

    github 不会使用,参照了其他大神的博客看的,很不错,就按步骤来,大家可以看看 http://www.cnblogs.com/wangzhongqiu/p/6243840.html

  2. 使用onepage-scroll全屏滚动插件时的注意事项

    如果项目需要在移动端访问时需要设置responsiveFallback属性,并且在此之前还需要检测浏览器的级别(引入modernizr.js文件) var $responsiveFallback = ...

  3. Linux 服务器配置JDK

    1. 查看java版本 [root@plttestap5 ~]# java -versionjava version "1.8.0_121"Java(TM) SE Runtime ...

  4. GCD(st表+二分)

    GCD Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  5. Java防止XSS攻击

    方法一:转义存储:添加XssFilter 1.在web.xml添加过滤器: <!-- 解决xss漏洞 --> <filter> <filter-name>xssFi ...

  6. iOS11 push控制器tabbar上移问题

    解决方法 - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { // 如果有大 ...

  7. Inside a super fast CSS engine: Quantum CSS (aka Stylo)

    https://hacks.mozilla.org/2017/08/inside-a-super-fast-css-engine-quantum-css-aka-stylo/?utm_source=d ...

  8. Full卷积 Same卷积 Vaild卷积

  9. fkwの题目(祝松松生日快乐!)

    麓山国际实验学校 傅少,匡哥和巨夫出的题目(共3道) 一.题目概况 题目名称 打地铺 泡妹子 开房间 题目类型 传统 传统 传统 可执行文件名 deeeep soccer room 输入文件名 dee ...

  10. Python 中奇妙的下划线

    单个下划线(_) 通常有三种用法: 在python解释器: 单个下划线代表上次在交互解释期对话中(控制台)执行的结果.这种情况在标准的CPython解释器中首次被实现,接下来这种习惯也被保持下来: & ...