#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#define maxn 110
#define pa pair<int,int>
using namespace std;
int n,num,head[maxn],dis[maxn],ans,len=0x7fffffff,f[maxn];
struct node
{
int u,v,t,pre;
}e[maxn*maxn];
void Add(int from,int to,int dis)
{
num++;
e[num].v=to;
e[num].u=from;
e[num].t=dis;
e[num].pre=head[from];
head[from]=num;
}
void Dij(int s)
{
priority_queue<pa,vector<pa>,greater<pa> >q;
q.push(make_pair(,s));
dis[s]=;
while(!q.empty())
{
int k=q.top().second;
q.pop();
if(f[k])continue;
f[k]=;
for(int i=head[k];i;i=e[i].pre)
if(dis[e[i].v]>dis[k]+e[i].t)
{
dis[e[i].v]=dis[k]+e[i].t;
q.push(make_pair(dis[e[i].v],e[i].v));
}
}
}
int main()
{
while()
{
scanf("%d",&n);
if(n==)break;
num=;ans=;len=0x7fffffff;
memset(head,,sizeof(head));
int x,y,z;
for(int i=;i<=n;i++)
{
scanf("%d%",&x);
for(int j=;j<=x;j++)
{
scanf("%d%d",&y,&z);
Add(i,y,z);
}
}
for(int i=;i<=n;i++)
{
memset(dis,/,sizeof(dis));
memset(f,,sizeof(f));
Dij(i);
int falg=,maxx=;
for(int j=;j<=n;j++)
{
if(dis[i]>)falg=;
maxx=max(maxx,dis[j]);
}
if(falg==)continue;
else
{
if(len>maxx)
{
len=maxx;
ans=i;
}
}
}
if(ans)printf("%d %d\n",ans,len);
else printf("disjoint\n");
}
}

poj 1125 Stockbroker Grapevine (dij优化 0ms)的更多相关文章

  1. 最短路(Floyd_Warshall) POJ 1125 Stockbroker Grapevine

    题目传送门 /* 最短路:Floyd模板题 主要是两点最短的距离和起始位置 http://blog.csdn.net/y990041769/article/details/37955253 */ #i ...

  2. POJ 1125 Stockbroker Grapevine【floyd简单应用】

    链接: http://poj.org/problem?id=1125 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  3. OpenJudge/Poj 1125 Stockbroker Grapevine

    1.链接地址: http://poj.org/problem?id=1125 http://bailian.openjudge.cn/practice/1125 2.题目: Stockbroker G ...

  4. poj 1125 Stockbroker Grapevine dijkstra算法实现最短路径

    点击打开链接 Stockbroker Grapevine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23760   Ac ...

  5. POJ 1125 Stockbroker Grapevine

    Stockbroker Grapevine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33141   Accepted: ...

  6. poj 1125 Stockbroker Grapevine(多源最短)

    id=1125">链接:poj 1125 题意:输入n个经纪人,以及他们之间传播谣言所需的时间, 问从哪个人開始传播使得全部人知道所需时间最少.这个最少时间是多少 分析:由于谣言传播是 ...

  7. POJ 1125 Stockbroker Grapevine 最短路 难度:0

    http://poj.org/problem?id=1125 #include <iostream> #include <cstring> using namespace st ...

  8. POJ 1125 Stockbroker Grapevine(floyd)

    http://poj.org/problem?id=1125 题意 : 就是说想要在股票经纪人中传播谣言,先告诉一个人,然后让他传播给其他所有的经纪人,需要输出的是从谁开始传播需要的时间最短,输出这个 ...

  9. poj 1125 Stockbroker Grapevine(最短路 简单 floyd)

    题目:http://poj.org/problem?id=1125 题意:给出一个社交网络,每个人有几个别人可以传播谣言,传播谣言需要时间.问要使得谣言传播的最快,应该从那个人开始传播谣言以及使得所有 ...

随机推荐

  1. C++实现红黑树,仿STL封装

    //RB_Tree.hpp //The code of red black trees //2011/12/31 by Adoo // The foundation :http://www.roadi ...

  2. hadoop各版本下载

    http://hadoop.apache.org/ Download Hadoop from the release page. http://hadoop.apache.org/releases.h ...

  3. Sort it all out

    poj1094:http://poj.org/problem?id=1094 题解(一位大神的分析) 一.当输入的字母全部都在前n个大写字母范围内时: (1)最终的图 可以排序: 在输入结束前如果能得 ...

  4. LINUX-LXC要好好关注下

    因为我觉得轻量极虚拟化可能是云的另一个发展方向. 至少,腾讯的WEB云引擎是以此为基础. LXC结合DOCKER.相信是快速云的另一种实现. 余下的,只是结合生产系统围绕这一中心进行的的二次开了. I ...

  5. bcb 如何在DLL中捕捉系统级异常

    http://topic.csdn.net/t/20031023/09/2385627.html -------------------------------------------------- ...

  6. fedora下体验gentoo安装

    服务器上安装了fedora,但是对gentoo很想体验一番,没有新机器,不想重装系统,所以只能chroot来体验getoo了. 下载portage-20130817.tar.bz2和stage3-am ...

  7. Unity GUI编程

    脚本语言:C# 附上一张图说明Unity GUI编程中可用的控件:(可能有遗漏) 下面列出一些例子来说明: 1.Groups : 在固定Layout模式中起到组织可用项的功能,它让你在屏幕的一个区域中 ...

  8. 数学(欧拉函数):UVAOJ 11426 GCD - Extreme (II)

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB4AAAAQ4CAIAAABnsVYUAAAgAElEQVR4nOzdPW7zvII/bG1gCi9gKq ...

  9. Dinic 模板

    #include <iostream> #include <cstring> #include <cstdio> #include <queue> us ...

  10. Codeforces Round #259 (Div. 2) D. Little Pony and Harmony Chest 状压DP

    D. Little Pony and Harmony Chest   Princess Twilight went to Celestia and Luna's old castle to resea ...