POJ1125 Stockbroker Grapevine(最短路)
题目链接。
分析:
手感不错,1A。
直接穷举的起点, 求出不同起点到其它点最短路中最长的一条的最小值(好绕)。
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; const int maxn = +;
const int INF = (<<); int n, G[maxn][maxn], d[maxn]; int dijkstra(int s) {
bool vis[maxn]; memset(vis, , sizeof(vis));
for(int i=; i<n; i++) {
d[i] = G[s][i];
}
d[s] = ; vis[s] = true; for(int i=; i<n-; i++) {
int x, m = INF;
for(int y=; y<n; y++) if(!vis[y] && m >= d[y]) m = d[x=y];
vis[x] = true;
for(int y=; y<n; y++) if(!vis[y] && d[y] > d[x]+G[x][y]) {
d[y] = d[x] + G[x][y];
}
} int ans = -;
for(int i=; i<n; i++) {
if(i == s) continue;
ans = max(ans, d[i]);
} return ans;
} int main() {
int m, v, c; while(scanf("%d", &n) == && n != ) {
for(int i=; i<n; i++)
for(int j=; j<n; j++)
G[i][j] = INF; for(int u=; u<n; u++) {
scanf("%d", &m);
for(int i=; i<m; i++) {
scanf("%d %d", &v, &c);
v--;
G[u][v] = c;
}
} int ans = INF, k;
for(int i=; i<n; i++) {
int res = dijkstra(i);
if(res == -) {
ans = -; break;
}
else if(ans > res) {
ans = res;
k = i;
}
} if(ans != INF) printf("%d %d\n", k+, ans);
else printf("disjoint\n");
} return ;
}
POJ1125 Stockbroker Grapevine(最短路)的更多相关文章
- POJ1125 Stockbroker Grapevine 多源最短路
题目大意 给定一个图,问从某一个顶点出发,到其它顶点的最短路的最大距离最短的情况下,是从哪个顶点出发?须要多久? (假设有人一直没有联络,输出disjoint) 解题思路 Floyd不解释 代码 #i ...
- POJ1125 Stockbroker Grapevine
Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a me ...
- POJ1125 Stockbroker Grapevine(spfa枚举)
Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a me ...
- POJ 1125 Stockbroker Grapevine 最短路 难度:0
http://poj.org/problem?id=1125 #include <iostream> #include <cstring> using namespace st ...
- poj1125 Stockbroker Grapevine Floyd
题目链接:http://poj.org/problem?id=1125 主要是读懂题意 然后就很简单了 floyd算法的应用 代码: #include<iostream> #include ...
- 【POJ 1125】Stockbroker Grapevine
id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...
- 最短路(Floyd_Warshall) POJ 1125 Stockbroker Grapevine
题目传送门 /* 最短路:Floyd模板题 主要是两点最短的距离和起始位置 http://blog.csdn.net/y990041769/article/details/37955253 */ #i ...
- Stockbroker Grapevine(最短路)
poj——1125 Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 36112 ...
- Stockbroker Grapevine(floyd+暴力枚举)
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31264 Accepted: 171 ...
随机推荐
- SAP-MM:发票、贷方凭证、事后借记、后续贷记
发票和事后借记 相同点:增加对供应商的应付款 不同点:针对同一订单收货,发票要先于事后借记(事后借记是对供应商后期发票金额的补充):发票和金额.订单数量有关系,而事后借记只是订单金额调整的凭证,仅仅是 ...
- Tomcat中Listener的使用范例(转载http://cywhoyi.iteye.com/blog/2075848)
Tomcat是非常有名的开源容器,因其开源我们可以对其做定制化的改变,而且Tomcat在其配置文件方面做了很多注释说明摘要,帮助我们更好的定制化我们所需的功能点. New Tomcat Listene ...
- ADLINK 8158控制程序-连续运动(VB.NET)
运动平台:日脉的二维运动平台(一个旋转平台和一个滑动平台) 开发环境:VS2010 + .NET Framework + VB.NET 使用文件:pci_8158.vb motion_8158_2D. ...
- 第二部分面向对像基础第五章Strng类中方法的使用
package com.java.oop.day2; import java.util.Calendar; import java.util.Formatter; import java.util.L ...
- SQL Server 2008创建定期自动备份任务
首先需要启动SQL Server Agent服务,这个服务如果不启动是无法运行新建作业的,点击“开始”–“所有程序”–“Microsoft SQL Server 2008”–“启动SQL Server ...
- oracle中创建一个用户,只能查看指定的视图,如何授权,创建别名
1.create user A identified by Apassword,创建用户,用户名是A,密码是Apassword2.grant connect to A --授予connect权限3.g ...
- 实现textarea限制输入字数
实现textarea限制输入字数(包含中文只能输入10个,全ASCII码能够输入20个) textarea称文本域,又称文本区,即有滚动条的多行文本输入控件,在网页的提交表单中经常用到.与单行文本框t ...
- wariging for you oh~
- Neutron/ML2学习
Neutron/ML2 Neutron ML2 模块层2(ml2)插件是一种允许OpenStack网络同时地利用在复杂现实数据中心发现的各种第二层网络技术的框架.目前它与存在的openvswitch. ...
- shell每日发邮件
LOGFILE="$fank/"`date +"%Y%m%d"`"data"#每日文件 from="abc@123.com&quo ...