BC#53 1001 Rikka with Graph

Rikka with Graph

Accepts: 353

Submissions: 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.

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <algorithm>
 4 using namespace std;
 5
 6 int main()
 7 {
 8     int n,m;
 9     int i,j,k;
10     while(scanf("%d %d",&n,&m)!=EOF)
11     {
12         int flg=0;
13         for(i=1;i<=m;i++)
14         {
15             int x,y;
16             scanf("%d %d",&x,&y);
17             if((x==1 && y==n)|| (x==n && y==1))
18                 flg=1;
19         }
20         if(flg==0)
21             printf("1 1\n");
22         else
23             printf("1 %d\n",n*(n-1)/2);
24     }
25     return 0;
26 }

时间: 2024-10-31 04:35:30

BC#53 1001 Rikka with Graph的相关文章

BC #53 1002 Rikka with Tree

Rikka with Tree Accepts: 207 Submissions: 815 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 t

HDU 5422:Rikka with Graph

Rikka with Graph Accepts: 353 Submissions: 1174 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 众所周知,萌萌哒六花不擅长数学,所以勇太给了她一些数学问题做练习,其中有一道是这样的: 勇太有一张nn个点mm条边的无向图,每一条边的长度都是1.现在他想再在这张图上连上一条连接两个不同顶点边,使得1号点到nn号点的最短路尽可能的短

hdu 5424 Rikka with Graph II 哈密顿通路

Rikka with Graph II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 367    Accepted Submission(s): 90 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situatio

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

Rikka with Graph II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1051    Accepted Submission(s): 266 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situati

HDU 4907 (杭电BC#3 1001)Task schedule(水)

题目地址:HDU 4907 水题...不多说..哈希后从后往前遍历一遍就行了. 代码如下: #include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <queue> #include <map> #include<a

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) 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

hdu 6090 Rikka with Graph

Rikka with Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 425    Accepted Submission(s): 270 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation,

hdu 5364 (bc#50 1001) Distribution money

Distribution money Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 276    Accepted Submission(s): 163 Problem Description AFA want to distribution her money to somebody.She divide her money into

HDU 4883 (BC#2 1001题)TIANKENG’s restaurant(水)

题目地址:HDU 4883 唉..最近得了一种惯性..刚学了什么就碰到个类似的就想用刚学的算法...原来这题如此简单..当时真是想多了.... 只要在需要变化的点上设置一个值,是增多少还是减多少.然后当遍历过来的时候加上或减去这个值就行了... 代码如下: #include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h>