题目链接

分析:

手感不错,1A。

直接穷举的起点, 求出不同起点到其它点最短路中最长的一条的最小值(好绕)。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. const int maxn = +;
  8. const int INF = (<<);
  9.  
  10. int n, G[maxn][maxn], d[maxn];
  11.  
  12. int dijkstra(int s) {
  13. bool vis[maxn];
  14.  
  15. memset(vis, , sizeof(vis));
  16. for(int i=; i<n; i++) {
  17. d[i] = G[s][i];
  18. }
  19. d[s] = ; vis[s] = true;
  20.  
  21. for(int i=; i<n-; i++) {
  22. int x, m = INF;
  23. for(int y=; y<n; y++) if(!vis[y] && m >= d[y]) m = d[x=y];
  24. vis[x] = true;
  25. for(int y=; y<n; y++) if(!vis[y] && d[y] > d[x]+G[x][y]) {
  26. d[y] = d[x] + G[x][y];
  27. }
  28. }
  29.  
  30. int ans = -;
  31. for(int i=; i<n; i++) {
  32. if(i == s) continue;
  33. ans = max(ans, d[i]);
  34. }
  35.  
  36. return ans;
  37. }
  38.  
  39. int main() {
  40. int m, v, c;
  41.  
  42. while(scanf("%d", &n) == && n != ) {
  43. for(int i=; i<n; i++)
  44. for(int j=; j<n; j++)
  45. G[i][j] = INF;
  46.  
  47. for(int u=; u<n; u++) {
  48. scanf("%d", &m);
  49. for(int i=; i<m; i++) {
  50. scanf("%d %d", &v, &c);
  51. v--;
  52. G[u][v] = c;
  53. }
  54. }
  55.  
  56. int ans = INF, k;
  57. for(int i=; i<n; i++) {
  58. int res = dijkstra(i);
  59. if(res == -) {
  60. ans = -; break;
  61. }
  62. else if(ans > res) {
  63. ans = res;
  64. k = i;
  65. }
  66. }
  67.  
  68. if(ans != INF) printf("%d %d\n", k+, ans);
  69. else printf("disjoint\n");
  70. }
  71.  
  72. return ;
  73. }

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. POJ 1686 Lazy Math Instructor (模似题+栈的运用) 各种坑

    Problem Description A math instructor is too lazy to grade a question in the exam papers in which st ...

  2. 利用NIO建立Socket服务器

    传统的Java 的IO,利用Socket建立服务器,接收客户端连接,一般都是为每一个连接建立一个线程,如果连接数巨大,那么服务器开销也将巨大..NIO的原理,可以参照图:http://new.51ct ...

  3. spring mvc使用ClassPathXmlApplicationContext或FileSystemXmlApplicationContext和XmlWebApplicationContext类的操作其中 XmlWebApplicationContext是专为Web工程定制的。

    一.简单的用ApplicationContext做测试的话,获得Spring中定义的Bean实例(对象).可以用: ApplicationContext ac = new ClassPathXmlAp ...

  4. [Javascrip] Logging Timing Data to the Console

    Learn to use console.time with console.timeEnd to get accurate timings of operations in javascript. ...

  5. 解决java.sql.SQLException: Parameter number X is not an OUT parameter--转

    最近独自一个人写项目,孤军奋战的程序猿可真伤不起! Java 调用MYSQL带输入输出参数存储过程时如题错误:java.sql.SQLException: Parameter number X is ...

  6. 0_Linux_虚拟机安装

    虚拟机的安装0Snapshot和clone 系统分区(由硬盘的性能所限制的) 1分区类型: 主分区:最多有4个 扩展分区:最多只能有1个:主分区加扩展分区最多有4个:不能写入数据,只能包含逻辑分区,不 ...

  7. VS2008 快捷键大全--------<<转>>

    VS2008 快捷键大全   Ctrl+E,D ----             格式化全部代码 Ctrl+K,F ----             格式化选中的代码 CTRL + SHIFT + B ...

  8. OD: Peimei & Versioning Analysis

    PE 中漫步—“白眉” 指令追踪技术与 Paimei 程序异常发生的位置通常离漏洞函数很远,当溢出发生时,栈帧往往也会遭到破坏,给动态调试制造很大的困难. 指令追踪最大限度地结合了动态分析和静态分析的 ...

  9. carousel

    <!DOCTYPE html> <html lang="en" ng-app="mainApp"> <head> <m ...

  10. OpenGL ES 3.0 顶点缓冲区VBO使用

    一般情况下数据都是有CPU从RAM取数据 然后传给GPU去处理,相对于GPU速度要慢一些. 使用VBO技术 可以把数据存储到GPU的内存空间中,这样GPU可以直接从GPU的内存中取得数据进行处理 速度 ...