POJ1125 Stockbroker Grapevine 多源最短路

题目大意

给定一个图,问从某一个顶点出发,到其他顶点的最短路的最大距离最短的情况下,是从哪个顶点出发?需要多久?

(如果有人一直没有联络,输出disjoint)

解题思路

Floyd不解释

代码

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int INF = 1000000000;
const int maxn = 110;
int d[maxn][maxn];
int n;
int main()
{
    //freopen("in.txt","r",stdin);
    while(scanf("%d",&n) && n) {
        for(int i = 0 ; i < maxn ; i ++) {
            fill(d[i],d[i]+maxn,INF);
        }
        for(int i = 0 ; i < maxn ; i ++) d[i][i] = 0;
        for(int i = 1 ; i <= n ; i ++) {
            int t;
            scanf("%d",&t);
            while(t--) {
                int a,b;
                scanf("%d%d",&a,&b);
                d[i][a] = b;
            }
        }
        for(int k = 1 ; k <= n ; k ++) {
            for(int i = 1 ; i <= n ; i ++) {
                for(int j = 1 ; j <= n ; j ++) {
                    d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
                }
            }
        }
        int mi = INF;
        int mark;
        for(int i = 1 ; i <= n ; i ++) {
            int ma = -1;
            for(int j = 1 ; j <= n ; j ++) {
                if(ma < d[i][j]) ma = d[i][j];
            }
            if(ma < mi) {
                mi = ma;
                mark = i;
            }
        }
        if(mi < INF) {
            printf("%d %d\n",mark,mi);
        }else printf("disjoint\n");
    }
    return 0;
}
时间: 2024-10-10 00:28:45

POJ1125 Stockbroker Grapevine 多源最短路的相关文章

POJ1125 Stockbroker Grapevine 多源最短路 Floyd

Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spreading disinformation amongst the stockbrokers to give your employer the tactical edge in the stock market. For maximum effect, you have to

poj1125 Stockbroker Grapevine 最短路 dijkstral + 优先队列

// poj1125 Stockbroker Grapevine 最短路 dijkstral + 优先队列 // // 一个模板吧,留着纪念 #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <queue> using namespace std; typedef pair<int,int> P; const i

POJ1125 Stockbroker Grapevine【Floyd】

Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 27977 Accepted: 15527 Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spreading disinformation amongst the st

POJ1125——Stockbroker Grapevine

Stockbroker Grapevine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 27547   Accepted: 15264 Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spreading disinformation amongst th

POJ1125 Stockbroker Grapevine 【Floyd】

Stockbroker Grapevine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 27431   Accepted: 15201 Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spreading disinformation amongst th

POJ1125 Stockbroker Grapevine

Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spreading disinformation amongst the stockbrokers to give your employer the tactical edge in the stock market. For maximum effect, you have to

poj 1125 Stockbroker Grapevine(多源最短路)

链接:poj 1125 题意:输入n个经纪人,以及他们之间传播谣言所需的时间, 问从哪个人开始传播使得所有人知道所需时间最少,这个最少时间是多少 分析:因为谣言传播是同时的,对于某条路径使得所有人都知道的时间,不是时间的总和,而是路径中最长的边 从多条路径的最长边,找出最小值,因为为多源最短路,用Floyd比较方便 #include<stdio.h> #include<limits.h> int a[105][105]; void floyd(int n) { int i,j,k,

poj 1125 Stockbroker Grapevine -- floyd 全源最短路

Stockbroker Grapevine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33164   Accepted: 18259 Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spreading disinformation amongst th

Stockbroker Grapevine(最短路_floyd())

Stockbroker Grapevine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 27478   Accepted: 15223 Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spreading disinformation amongst th