题目链接

分析:

手感不错,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. javascript中错误使用var造成undefined

    在javascript中依据变量作用的范围不同分为局部变量和全局变量,直接定义的变量是全局变量,全局变量能够被全部的脚本訪问:在函数中定义的变量是局部变量,局部变量仅仅在函数内有效. 假设全局变量和局 ...

  2. HDU 1548 A strange lift 搜索

    A strange lift Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  3. “too many open files" ----增大打开的文件数

     http://www.cnblogs.com/ibook360/archive/2012/05/11/2495405.html [root@localhost ~]# ab -n -c http:/ ...

  4. [转] prerender-SPA程序的SEO优化策略

    随着web2.0的兴起,ajax的时代已经成为了事实,更如今 Knockout,backbone, angular,ember前端MDV(model driver view)框架强势而来,Single ...

  5. Android短信的发送和接收监听

    /**发送与接收的广播**/ String SENT_SMS_ACTION = "SENT_SMS_ACTION"; String DELIVERED_SMS_ACTION = & ...

  6. Android WindowManager的使用

    经常,我们看到在桌面上可移动的悬浮窗,这种场景还是很多的, 像流量统计,桌面歌词等,安全软件的清理小部件 这种小部件主要是通过 WindowManager ; WindowManager.Layout ...

  7. PHP接口的声明与引用

    PHP接口的声明与引用 <?php//遵循规律:先继承,后接口//单继承,多接口class lei{function fangfa(){return "中国电信提醒您:<br&g ...

  8. BeautifulSoup在Windows下安装(running 2to3)

    在windows下安装beautifulsoup经常会出现说是在python3下无法运行Python2的代码,这时需要将Python下的tool下的scripts目录添加到环境变量中,然后运行2to3 ...

  9. Python开发【第七篇】:面向对象 和 python面向对象进阶篇(下)

    Python开发[第七篇]:面向对象   详见:<Python之路[第五篇]:面向对象及相关> python 面向对象(进阶篇)   上一篇<Python 面向对象(初级篇)> ...

  10. 关于android应用闪屏的几种情况

    1.主菜单进入某应用闪屏: 常见是一个空的activity作为launcher属性,实际上它什么事业没干,真正干事情的是从它通过intent启动的activity. 例子: public class ...