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 ...
随机推荐
- POJ 1686 Lazy Math Instructor (模似题+栈的运用) 各种坑
Problem Description A math instructor is too lazy to grade a question in the exam papers in which st ...
- 利用NIO建立Socket服务器
传统的Java 的IO,利用Socket建立服务器,接收客户端连接,一般都是为每一个连接建立一个线程,如果连接数巨大,那么服务器开销也将巨大..NIO的原理,可以参照图:http://new.51ct ...
- spring mvc使用ClassPathXmlApplicationContext或FileSystemXmlApplicationContext和XmlWebApplicationContext类的操作其中 XmlWebApplicationContext是专为Web工程定制的。
一.简单的用ApplicationContext做测试的话,获得Spring中定义的Bean实例(对象).可以用: ApplicationContext ac = new ClassPathXmlAp ...
- [Javascrip] Logging Timing Data to the Console
Learn to use console.time with console.timeEnd to get accurate timings of operations in javascript. ...
- 解决java.sql.SQLException: Parameter number X is not an OUT parameter--转
最近独自一个人写项目,孤军奋战的程序猿可真伤不起! Java 调用MYSQL带输入输出参数存储过程时如题错误:java.sql.SQLException: Parameter number X is ...
- 0_Linux_虚拟机安装
虚拟机的安装0Snapshot和clone 系统分区(由硬盘的性能所限制的) 1分区类型: 主分区:最多有4个 扩展分区:最多只能有1个:主分区加扩展分区最多有4个:不能写入数据,只能包含逻辑分区,不 ...
- VS2008 快捷键大全--------<<转>>
VS2008 快捷键大全 Ctrl+E,D ---- 格式化全部代码 Ctrl+K,F ---- 格式化选中的代码 CTRL + SHIFT + B ...
- OD: Peimei & Versioning Analysis
PE 中漫步—“白眉” 指令追踪技术与 Paimei 程序异常发生的位置通常离漏洞函数很远,当溢出发生时,栈帧往往也会遭到破坏,给动态调试制造很大的困难. 指令追踪最大限度地结合了动态分析和静态分析的 ...
- carousel
<!DOCTYPE html> <html lang="en" ng-app="mainApp"> <head> <m ...
- OpenGL ES 3.0 顶点缓冲区VBO使用
一般情况下数据都是有CPU从RAM取数据 然后传给GPU去处理,相对于GPU速度要慢一些. 使用VBO技术 可以把数据存储到GPU的内存空间中,这样GPU可以直接从GPU的内存中取得数据进行处理 速度 ...