ACM学习历程—HDU5422 Rikka with Graph(贪心)
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?
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.
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。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <vector>
#define LL long long using namespace std; int n, m;
bool dis[][]; int input()
{
if (scanf("%d%d", &n, &m) == EOF)
return false;
memset(dis, false, sizeof(dis));
int u, v;
for (int i = ; i < m; ++i)
{
scanf("%d%d", &u, &v);
dis[u][v] = dis[v][u] = true;
}
return true;
} void work()
{
printf("1 ");
if (dis[][n])
printf("%d\n", n*(n-)/);
else
printf("1\n");
} int main()
{
//freopen("test.in", "r", stdin);
while (input())
{
work();
}
return ;
}
ACM学习历程—HDU5422 Rikka with Graph(贪心)的更多相关文章
- ACM学习历程—HDU5423 Rikka with Tree(搜索)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- ACM学习历程——NOJ1113 Game I(贪心 || 线段树)
Description 尼克发明了这样一个游戏:在一个坐标轴上,有一些圆,这些圆的圆心都在x轴上,现在给定一个x轴上的点,保证该点没有在这些圆内(以及圆上),尼克可以以这个点为圆心做任意大小的圆,他想 ...
- ACM学习历程——HDU5202 Rikka with string(dfs,回文字符串)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- ACM学习历程—CSU 1216 异或最大值(xor && 贪心 && 字典树)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1216 题目大意是给了n个数,然后取出两个数,使得xor值最大. 首先暴力枚举是C(n, ...
- ACM学习历程—HihoCoder1309任务分配(排序 && 贪心)
http://hihocoder.com/problemset/problem/1309 题目大意是给定n个任务的起始时间,求问最少需要多少台机器. 有一个贪心的策略就是,如果说对于一个任务结束,必然 ...
- ACM学习历程—HDU4415 Assassin’s Creed(贪心)
Problem Description Ezio Auditore is a great master as an assassin. Now he has prowled in the enemie ...
- ACM学习历程—FZU 2144 Shooting Game(计算几何 && 贪心 && 排序)
Description Fat brother and Maze are playing a kind of special (hentai) game in the playground. (May ...
- ACM学习历程—HDU 4726 Kia's Calculation( 贪心&&计数排序)
DescriptionDoctor Ghee is teaching Kia how to calculate the sum of two integers. But Kia is so carel ...
- 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 ...
随机推荐
- Android 热门技术干货
http://mp.weixin.qq.com/s?__biz=MzIwMzYwMTk1NA==&mid=2247484939&idx=1&sn=d1871b09de55ca6 ...
- List和Set排序的实现
List.Set.Map的区别 List和Set继承了Collection接口. List以特定索引来存取元素,可以有重复元素.Set不能存放重复元素(用对象的equals()方法来区分元素是否重复) ...
- EasyNVR无插件直播服务器播放页面的集成----单独的播放器样式
背景需求: EasyNVR自身拥有独立的客户端体系,安卓和IOS拥有各自独立的APP, 安卓下载地址:https://fir.im/EasyNVR: IOS下载可直接在APPstore搜索EasyNV ...
- 解决 SVN版本冲突
链接:http://blog.csdn.net/windone0109/article/details/4857044 版本冲突原因: 假设A.B两个用户都在版本号为100的时候,更新了kingtun ...
- 网络的分层协议总结(转发:https://www.cnblogs.com/Zhang-wj/p/5907534.html)
网络的分层协议总结 OSI七层模型OSI 中的层 功能 TCP/IP ...
- python实例2-写一个爬虫下载小功能
主要是通过url,和re两个模块对一个网页的固定图片进行模糊匹配后下载下来. #! /usr/bin/python import re import urllib def gethtml(url): ...
- linux 10 -Bash Shell编程
二十三. Bash Shell编程: 1. 读取用户变量: read命令是用于从终端或者文件中读取输入的内建命令,read命令读取整行输入,每行末尾的换行符不被读入.在read命令后 ...
- [原创]java WEB学习笔记36:Java Bean 概述,及在JSP 中的使用,原理
本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...
- 《python基础教程(第二版)》学习笔记 列表/元组(第2章)
<python基础教程(第二版)>学习笔记 列表/元组(第2章)序列中的下标从0开始x='ABC' ==> x[0]='A', x[1]='B', x[2]='C'负数索引从右边开始 ...
- lnmp 一键安装配置
l系统需求: CentOS/RHEL/Fedora/Debian/Ubuntu/Raspbian/Deepin Server/Aliyun/Amazon/Mint Linux发行版 需要5GB以上硬盘 ...