题目链接

分析:

手感不错,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. cocos2d_android开发简单游戏

    1)游戏图层设计: public class WellcomeLayer extends CCLayer { public WellcomeLayer() { this.setIsTouchEnabl ...

  2. Linux Kernel: buffers和cached的区别

    The page cache caches pages of files to optimize file I/O. The buffer cache caches disk blocks to op ...

  3. 再回首,Java温故知新(八):Java基础之字符串

    字符串是Java中使用频率最高的类,但是它却不属于基本类型,而是预定义了String类来表示.从String类的源码可以看到,String是基于char[]实现的,而且Java中的String是不可变 ...

  4. uva 11324 The Largest Clique (Tarjan+记忆化)

    /*每个环 要么不选 要么全选 可缩点 就得到一个GAD图 然后搞搞算出最大路径*/ #include<iostream> #include<cstdio> #include& ...

  5. 【开源java游戏框架libgdx专题】-13-开发工具-地图的使用

    支持libGDX的地图编辑器有很多种,其中比较常用的工具为Tiled地图工具.Tiled是一款非常好用的地图编辑器.下载地址:http://www.mapeditor.org TiledMap类: 又 ...

  6. Oracle中的over(partition by...)分析函数及开窗函数

    假设有一张表student Name  Score  InsertTime   (Name:姓名  Score:成绩 InsertTime:考试时间) 张三     20    2015-08-08 ...

  7. HDU3853

    题意:给R*C的迷宫,起点为1,1 终点为R,C 且给定方格所走方向的概率,分别为原地,下边,右边,求到终点的期望. 思路:既然是求到终点的期望,那么DP代表期望,所以DP[i][j]=原地的概率*D ...

  8. Wpf 数据绑定简介、实例1

    简介:1.WPF绑定使用的源属性必须是依赖项属性,这是因为依赖项属性具有内置的更改通知支持,元素绑定表达式使用了Xaml扩展标记, WPF绑定一个控件是使用Binding.ElementName, 绑 ...

  9. android - startActivity浅谈

    当执行startActivity(Intent intent, Bundle options)函数的时候,应用程序不是直接呼叫另外一个Activity,而是将intent传进Android框架中.An ...

  10. WebSocket协议

    websocket 简介 (2013-04-09 15:39:28) 转载▼   分类: websocket 一 WebSocket是html5新增加的一种通信协议,目前流行的浏览器都支持这个协议,例 ...