hdu 5422 Rikka with Graph
2015-08-29 21:23
323 查看
click here ~~
题目大意:众所周知,萌萌哒六花不擅长数学,所以勇太给了她一些数学问题做练习,其中有一道是这样的:
勇太有一张nn个点mm条边的无向图,每一条边的长度都是1。现在他想再在这张图上连上一条连接两个不同顶点边,使得1号点到nn号点的最短路尽可能的短。现在他想要知道最短路最短是多少,以及再保证最短路最短的情况下,他有多少种连边的方案。
当然,这个问题对于萌萌哒六花来说实在是太难了,你可以帮帮她吗?
解题思路:
考虑最短距离:很显然,所有情况下最短距离都是1。
考虑方案数:如果本来没有1-n的边,那么只能连1-n,方案数为1;
否则怎么连都可以,方案数是(n-1)*n/2;
上代码:
[code] ***Rikka with Graph*** 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 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? Input There are no more than 100 testcases. 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. Output For each testcase, print a single line contains two numbers: The length of the shortest path between vertice 1 and vertice n and the number of the ways of adding this edge. Sample Input 2 1 1 2 Sample Output 1 1
题目大意:众所周知,萌萌哒六花不擅长数学,所以勇太给了她一些数学问题做练习,其中有一道是这样的:
勇太有一张nn个点mm条边的无向图,每一条边的长度都是1。现在他想再在这张图上连上一条连接两个不同顶点边,使得1号点到nn号点的最短路尽可能的短。现在他想要知道最短路最短是多少,以及再保证最短路最短的情况下,他有多少种连边的方案。
当然,这个问题对于萌萌哒六花来说实在是太难了,你可以帮帮她吗?
解题思路:
考虑最短距离:很显然,所有情况下最短距离都是1。
考虑方案数:如果本来没有1-n的边,那么只能连1-n,方案数为1;
否则怎么连都可以,方案数是(n-1)*n/2;
上代码:
[code]/* 2015 - 8 - 29 晚上 Author: ITAK 今日的我要超越昨日的我,明日的我要胜过今日的我, 以创作出更好的代码为目标,不断地超越自己。 */ #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; const int Max = 0xfffffff; const int maxn = 110; int dis[maxn][maxn]; int m, n, ans; //n代表结点个数 //m代表有几条边 int main() { while(cin>>n>>m) { memset(dis, 0, sizeof(dis)); int u, v, w; while(m--) { cin>>u>>v; dis[u][v] = 1; dis[v][u] = 1; } int ret; if(dis[1] == 1) ret = n*(n-1)/2; else ret = 1; cout<<1<<" "<<ret<<endl; } return 0; }
相关文章推荐
- Git远程操作详解
- Servlet和JSP学习指导与实践(二):Session追踪
- Emgucv SURF特征点的寻找和匹配
- SIFT算法详解
- 初识JAVA5(线程)
- Hibernate懒加载异常的解决与深刻分析
- 解析Tomcat处理请求的类Connector<1>
- ZooKeeper实现分布式队列Queue
- serverlet实现文件下载
- ASP.NET MVC导出excel
- 下拉刷新:继承listView控件
- HDU 2600 War(水题 区间边排序+贪心)
- 两段用php转义从而可以防止刷入的代码
- 使用phantomjs抓取JS动态生成的页面
- iOS 并发编程之 Operation Queues
- 3D图形渲染管线
- SIFT特征提取分析
- codeforces293E (树上点分治+树状数组)
- JS添加节点方法与JQuery添加节点方法的比较及总结
- UILabel 学习知识点