hdu 5422 Rikka with Graph(简单题)
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?
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.
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.
You can only add an edge between 1 and 2.
如果连上1-nnn的边,最短距离就是1。所以所有情况下最短距离都是1。
考虑方案数,如果本来没有1-nnn的边,那么只能连1-nnn,方案数为1。否则怎么连都可以,方案数是n(n−1)2\frac{n(n-1)}{2}2n(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(简单题)的更多相关文章
- HDU 5422 Rikka with Graph
Rikka with Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 5631 Rikka with Graph 暴力 并查集
Rikka with Graph 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5631 Description As we know, Rikka ...
- HDU 2802 F(N)(简单题,找循环解)
题目链接 F(N) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- HDU 6090 Rikka with Graph
Rikka with Graph 思路: 官方题解: 代码: #include<bits/stdc++.h> using namespace std; #define ll long lo ...
- HDU 5424——Rikka with Graph II——————【哈密顿路径】
Rikka with Graph II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- 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) ...
- 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 ...
- 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 ...
- HDU 5632 Rikka with Array [想法题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5632 ------------------------------------------------ ...
随机推荐
- AngularJs学习笔记6——四大特性之依赖注入
压缩工具:YUI-compressor 为了优化网页功能,对一些脚本文件进行压缩,比如:删除所有的注释和空格等,简化形参.但是AngularJs模块中可以声明多种组件,如控制器.指令.过滤器.服务等. ...
- 简单的通过NSFileManager 存储图片
UIImage *image = [UIImage imageNamed:@"Default.png"]; NSData *data = UIImageJPEGRepresenta ...
- Java当中的运算符
一.关于Java当中运算符的分类 算术运算符:+,-,*,/.%(是取余运算符读莫).++.-- 关系运算符:>.<.>=.<=.!=(不等).==(等于) 布尔运算符:!(非 ...
- Cortex-mo指令集
处理器使用的是ARMv6-M Thumb指令集,包括大量的32位的使用Thumb-2技术的指令.表7-22列出了Cortex-M0指令和它们的周期数.周期计数以零等待状态的系统为基准. 表7-22 ...
- Python序列的方法(转)
在快速教程中,我们了解了最基本的序列(sequence).回忆一下,序列包含有定值表(tuple)和表(list).此外,字符串(string)是一种特殊的定值表.表的元素可以更改,定值表一旦建立,其 ...
- ubuntu server 14.04.4 无线网卡没有启用,找不到wlan0端口
Ubuntu Server默认的情况下是不会启用无线网卡的,想想实际服务器上怎么可能有无线网卡呢,呵呵.所以我们需要手动来启用无线网卡,难点就在这里了. 使用ifconfig命令,发现没有wlan口, ...
- 高性能Java Web 页面静态化技术
package com.yancms.util; import java.io.*; import org.apache.commons.httpclient.*; import org.apache ...
- 有几数组表单,js怎么获得数组并动态相加输出到文本框
有几数组表单,js如何获得数组并动态相加输出到文本框<input name= "fee1[] "> <input name= "fee2[] & ...
- 获取GET/POST提交的数据,并处理中文问题
1.获取input标签中的值,用request.getParameter("User")(User为input的name值) 2. 获取checkbox的值,由于是多选的,所以不能 ...
- shell的string operator
${varname:-word} 如果varname存在并且不为nil,那么返回varname的值,否则返回word.这个常用来在varname未定义时返回默认值 ${varname:=word} 如 ...