题目链接

分析:

手感不错,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(最短路)的更多相关文章

  1. POJ1125 Stockbroker Grapevine 多源最短路

    题目大意 给定一个图,问从某一个顶点出发,到其它顶点的最短路的最大距离最短的情况下,是从哪个顶点出发?须要多久? (假设有人一直没有联络,输出disjoint) 解题思路 Floyd不解释 代码 #i ...

  2. POJ1125 Stockbroker Grapevine

    Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a me ...

  3. POJ1125 Stockbroker Grapevine(spfa枚举)

    Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a me ...

  4. POJ 1125 Stockbroker Grapevine 最短路 难度:0

    http://poj.org/problem?id=1125 #include <iostream> #include <cstring> using namespace st ...

  5. poj1125 Stockbroker Grapevine Floyd

    题目链接:http://poj.org/problem?id=1125 主要是读懂题意 然后就很简单了 floyd算法的应用 代码: #include<iostream> #include ...

  6. 【POJ 1125】Stockbroker Grapevine

    id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...

  7. 最短路(Floyd_Warshall) POJ 1125 Stockbroker Grapevine

    题目传送门 /* 最短路:Floyd模板题 主要是两点最短的距离和起始位置 http://blog.csdn.net/y990041769/article/details/37955253 */ #i ...

  8. Stockbroker Grapevine(最短路)

      poj——1125 Stockbroker Grapevine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 36112 ...

  9. Stockbroker Grapevine(floyd+暴力枚举)

    Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31264 Accepted: 171 ...

随机推荐

  1. C primer plus 读书笔记第十章

    这一章的标题是数组和指针.指针是C语言的精髓所在,而数组的概念和指针又息息相关,所以放在一起讲. 1.数组 主要内容有:1.1.数组初始化.1.2.指定初始化.1.3.数组赋值.1.4.数组边界.1. ...

  2. 3D游戏引擎一 win32编程

    Windows程序一般都等待用户进行一些操作,然后响应并採取行动. 一般来说.对win32的程序的操作都会转换为系统事件队列中的消息,如按键消息WM_KEYDOWN,WM_MOUSECLICK等传递键 ...

  3. 【PHP缩略图类】手机照片不能生成缩略图问题以及解决方式

    [本文原创,谢绝转载] 一.出现的问题 这几天做了手机上传照片并裁出缩略图的接口的測试,发现无论怎么.生成的缩略图都是一片漆黑.:-( 然后就把这个缩略图类单拿出来进行測试,发现仅仅要是手机拍出来的照 ...

  4. Java基础知识强化之IO流笔记19:FileOutputStream的三个write方法

    1. FileOutputStream的三个write方法:  void write(byte[] buffer)           Writes the entire contents of th ...

  5. win10的独立存储

    win10的独立存储和win8的大致相同 Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.Appl ...

  6. JavaScript--时间显示小插件

    JS调用系统时间,显示在当前页面上,利用DOM操作节点来实现动态刷新 <!DOCTYPE html> <html> <head> <meta charset= ...

  7. JY02-HTML/CSS-京东01 定位是很粗暴的页面布局方法

    1.学习重点 1. 独立完成开发前的准备工作 1.1 配置开发环境 已使用sublime,webstorm,,,vscode,ato,Hbuilder 1.2 建立项目文件 项目文件名/ css.js ...

  8. eclise -The method onClick(View) of type new View.OnClickListener(){} must override a superclass method

    在做arcgis android开发的时候,突然遇到这种错误,The method onClick(View) of type new View.OnClickListener(){} must ov ...

  9. iOS中使用UIWebView与JS进行交互

    iOS中使用UIWebView与JS进行交互 前一段忙着面试和复习,这两天终于考完试了,下学期的实习也有了着落,把最近学的东西更新一下,首先是使用UIWebView与JS进行交互 在webView中我 ...

  10. firefox 的event事件处理

    前几天,在用angularJs实现一个功能,点击后获取event的x,y坐标时,IE9, chrome下功能正常.但是firefox报event 未定义.初始代码如下: html: <div c ...