BC#53 1001 Rikka with Graph
2015-08-30 13:57
429 查看
Rikka with Graph
Accepts: 353Submissions: 1174
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
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 nn vertices and mm 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 nn. 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 \leq n \leq 100, 0 \leq m \leq 100)n,m(2≤n≤100,0≤m≤100).
Then mm lines follow. Each line contains two numbers u,v(1 \leq u,v \leq n)u,v(1≤u,v≤n) , which means there is an edge between uu and vv. 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 nn 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.
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; int main() { int n,m; int i,j,k; while(scanf("%d %d",&n,&m)!=EOF) { int flg=0; for(i=1;i<=m;i++) { int x,y; scanf("%d %d",&x,&y); if((x==1 && y==n)|| (x==n && y==1)) flg=1; } if(flg==0) printf("1 1\n"); else printf("1 %d\n",n*(n-1)/2); } return 0; }
View Code
相关文章推荐
- C#中的delegate与event简单讲解
- C#中堆和栈的区别分析
- C#基础案例------聊天机器人
- c#之内置类型
- C# WindowsEvent Select
- c# TextBox只允许输入数字,禁用右键粘贴,允许Ctrl+v粘贴数字
- C# - 委托的使用
- c#输出文件对话框
- c#格式化数字
- winform,C#,打开文件对话框的使用
- C# - 重写虚方法
- C# - 使用 List<> 泛型给GridView控件数据
- C#基础------字符串函数
- C# ref 和 out ,params关键字的用法
- CSharpGL(0)一个易学易用的C#版OpenGL
- ICSharpCode.SharpZipLib.dll 使用方法
- this(C#)
- this(C#)
- [C#] 等待启动的进程执行完毕
- C#-----多态