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 . Now he wants to add exactly an edge which connects two different vertices and minimize the length of the shortest path between vertice  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  testcases. 

For each testcase, the first line contains two numbers n,m(≤n≤,≤m≤).

Then m lines follow. Each line contains two numbers u,v(≤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  and vertice n and the number of the ways of adding this edge.

 
Sample Input
 

 
Sample Output
 
Hint

You can only add an edge between 1 and 2.

 
Source
 

如果连上1-nnn的边,最短距离就是1。所以所有情况下最短距离都是1。

考虑方案数,如果本来没有1-nnn的边,那么只能连1-nnn,方案数为1。否则怎么连都可以,方案数是n(n−1)2\frac{n(n-1)}{2}​2​​n(n−1)​​。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
#define N 106
int n,m;
int mp[N][N];
int main()
{
while(scanf("%d%d",&n,&m)==){
memset(mp,,sizeof(mp));
for(int i=;i<m;i++){
int u,v;
scanf("%d%d",&u,&v);
mp[u][v]=mp[v][u]=;
}
if(mp[][n]){
printf("1 ");
printf("%d\n",n*(n-)/);
}
else{
printf("1 ");
printf("1\n");
}
}
return ;
}

hdu 5422 Rikka with Graph(简单题)的更多相关文章

  1. HDU 5422 Rikka with Graph

    Rikka with Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  2. HDU 5631 Rikka with Graph 暴力 并查集

    Rikka with Graph 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5631 Description As we know, Rikka ...

  3. HDU 2802 F(N)(简单题,找循环解)

    题目链接 F(N) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  4. HDU 6090 Rikka with Graph

    Rikka with Graph 思路: 官方题解: 代码: #include<bits/stdc++.h> using namespace std; #define ll long lo ...

  5. HDU 5424——Rikka with Graph II——————【哈密顿路径】

    Rikka with Graph II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  6. HDU 6090 Rikka with Graph —— 2017 Multi-University Training 5

    Rikka with Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  7. hdu 5424 Rikka with Graph II(dfs+哈密顿路径)

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

  8. 2017ACM暑期多校联合训练 - Team 5 1006 HDU 5205 Rikka with Graph (找规律)

    题目链接 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, s ...

  9. HDU 5632 Rikka with Array [想法题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5632 ------------------------------------------------ ...

随机推荐

  1. 用python演示一个简单的AST(抽象语法树)

    如果对'a + 3 * b'进行解释,当中a=2,b=5 代码非常easy,就不再进行具体的解释了. Num = lambda env, n: n Var = lambda env, x: env[x ...

  2. linux od命令

    用户通常使用od命令查看特殊格式的文件内容.通过指定该命令的不同选项可以以十进制.八进制.十六进制和ASCII码来显示文件.od命令系统默认的显示方式是八进制,这也是该命令的名称由来(Octal Du ...

  3. nginx安装(正式)

    一.安装说明 系统环境:CentOS Linux release 7.2.1511 (Core) 系统内核:3.10.0-327.el7.x86_64软件:nginx-1.10.1.tar.gz其他所 ...

  4. Sass的控制命令(循环)

    @if@if指令是一个SassScript,它可以根据条件来处理样式块,如果条件为true返回一个样式块,反之false返回另一个样式块.在Sass中除了@if,还可以配合@else if和@else ...

  5. ReportViewer导出功能筛选

    ReportViewer只能导出Excel,把导出Word和PDF功能去掉 <rsweb:ReportViewer ID="ReportViewer1" runat=&quo ...

  6. Fragment实现底部Tab,切换可保存状态

    activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android& ...

  7. 16--Box2D使用(二、显示物理世界)

    在上一篇文章中我们创建了的一个物理世界,当物理世界中的刚体一个也没有显示出来.为显示物理世界中的物体,我们需要引入GLES-Render(调试Box2D使用).这两个文件可以再 %Cocos_Home ...

  8. Session生命周期讨论

    文章级别:Java初级    预备技能点:JSP内置对象, 监听器, 序列化           在程序开发的时候, request session appplication内置对象, 是用的比较多的 ...

  9. 带你深入了解Web站点数据库的分布存储

    作者:finalbsd原载: http://www.sanotes.net/html/y2009/358.html 在Web 2.0时代,网站将会经常面临着快速增加的访问量,但是我们的应用如何满足用户 ...

  10. Vim光标移动

    最近全面转换开发到Mac OS下,用MacVim作为IDE.记录一些Vim基本操作给自己备忘. 此次所说的都是在common-mode(c-mode,在Vim又名normal-mode,就是刚进入vi ...