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。

代码:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <set>
  7. #include <queue>
  8. #include <vector>
  9. #define LL long long
  10.  
  11. using namespace std;
  12.  
  13. int n, m;
  14. bool dis[][];
  15.  
  16. int input()
  17. {
  18. if (scanf("%d%d", &n, &m) == EOF)
  19. return false;
  20. memset(dis, false, sizeof(dis));
  21. int u, v;
  22. for (int i = ; i < m; ++i)
  23. {
  24. scanf("%d%d", &u, &v);
  25. dis[u][v] = dis[v][u] = true;
  26. }
  27. return true;
  28. }
  29.  
  30. void work()
  31. {
  32. printf("1 ");
  33. if (dis[][n])
  34. printf("%d\n", n*(n-)/);
  35. else
  36. printf("1\n");
  37. }
  38.  
  39. int main()
  40. {
  41. //freopen("test.in", "r", stdin);
  42. while (input())
  43. {
  44. work();
  45. }
  46. return ;
  47. }

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. B. Worms Codeforces Round #271 (div2)

    B. Worms time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  2. 实用T-SQL代码

    1.根据出生日期计算当前已满周岁 DECLARE @birth datetime SET @birth='1990-01-01' ),) ),) 2.COUNT(expression) just re ...

  3. EF中几个重要的类:ObjectContext、ObjectQuery、ObjectStateEntry、ObjectStateManager

    ObjectContext封装 .NET Framework 和数据库之间的连接.此类用作“创建”.“读取”.“更新”和“删除”操作的网关. ObjectContext 类为主类,用于与作为对象(这些 ...

  4. PhotoKit详解

    Photokit介绍 这篇主要介绍如何通过 Photokit获取数据 photokit.jpg 1,基类 PHObject Photos 框架中的根类PHObject只有一个公开接口 localIde ...

  5. 为system对象添加扩展方法

    ////扩展方法类:必须为非嵌套,非泛型的静态类 public static class DatetimeEx { //通过this声明扩展的类,这里给DateTime类扩展一个Show方法,只有一个 ...

  6. Bootstrap学习-导航条-分页导航

    1.导航条基础 导航条(navbar)和上一节介绍的导航(nav),就相差一个字,多了一个“条”字.其实在Bootstrap框架中他们还是明显的区别.在导航条(navbar)中有一个背景色.而且导航条 ...

  7. 我的Android进阶之旅------>Android关于Log的一个简单封装

    android.util.Log类,可以方便地用于在编码调试过程中打印日志.但是在发布后的产品中,如果有太多的日志打印,则会严重地影响性能.对android.util.Log类做一个简单的封装,当产品 ...

  8. C#练习DataReader

    SQL代码: create database ThreeDb go USE ThreeDb; GO CREATE TABLE classify --分类表 ( id ,), name ) not nu ...

  9. Eclipse cdt mingw配置记录

    本人下载的是Eclipse C/C++ IDE for Neon.3,下载页面是:http://www.eclipse.org/cdt/downloads.php. 1. 运行eclipse后,在He ...

  10. 《程序员代码面试指南》第一章 栈和队列 最大值减去最小值小于或等于num的数量

    题目 给定整数数组arr和整数num,共返回多少的数组满足如下情况 max(arr[i...j]) - min(arr[i...j]) <= num max(arr[i...j])表示数组arr ...