POJ-1125(Stockbraker Graphvine)

4313 ワード

Stockbrook er Graphvine
テーマリンク:
http://poj.org/problem?id=1125
タイトル:
Time Limit: 1000 MS
 
メモリLimit: 100000 K
Total Submissions: 39459
 
Acceepted: 22024
Description
Stockbrook ers are known to overreact to rumours.You have been contraced to develop a method of spreading disinformation amongst the stockbrook ers to give your emboyer the Tactical edge the stock maker.Foremut。  Unfortunally for you,stockbbreokers only trust information comotion ffrom their「Trusted sources」This means ouhave to tae into account the stststststucture of theirconcts when starting a rumoure.It tatatas s aceststininininininaaaaaststststststststststststststststrererereaaaaaaaaaaaaaaaastststststststststststststststststststststststststaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaawhich stockbrook erto chose as your starting point for the rumour、as well as the time it will Tale for the rumour to spread throughot the stockbration communit.This duration is meas the time need for the last person for inceive.
Input
Your program will input data for different sets of stockbrook ers.Each set starts with a line with the number of stockbrook ers.Follwing this a line for each stockbrook which contains the number the opapeareそして、the time Tanen for them to pass the message to each person.The format of each stockbrook line is as follows:The line starts with the number of concts(n)、followed byn pairs of integers、one parererererererettttpairt.parerereaaaaaaparererererererereretttttts.parererererererererereretttttttttttts.s.s.parererererererereaaaaaaaaaaaaaaaaaaaaaaaone in the set)フォロwed by the time in minutes Tanes to pass a message to that person.The re areのspecial punction smbors or spacing rules.  Each person is numberd 1 through to the number of stockbrook ers.The time Taen to pass the message on will be between 1 and 10 minutes、and the number of contacts will range between 0 and one less than the number of stockbrook ers.The number of stockbrook ers will range from 1 to 100.The input is terminated by a set of stockbrook ers containing 0   
Output
For each set of data、your program must output a single line containing the person who reults in the fastest message transmission、and how long before the last person will reive any given message of the givent fter givent in it。  It is possible that your program will receive a network of connects that excludes some persons,i.e.some people may be unreachable.If your program detects such a brook network,simply output the message「disject」.Note that the time Taen to pass the message from person A to person B is not necessary the same as the time taen to pass it from B to A,if such transmission possible.
Sample Input
3
2 2 4 3 5
2 1 2 3 6
2 1 2 2 2
5
3 4 4 2 8 5 3
1 5 8
4 1 6 4 10 2 7 5 2
0
2 2 5 1 5
0
Sample Output
3 2
3 10
タイトルの意味:
あなたにn人をあげます 一人一人に情報を伝える時間(二人が互いに情報を伝える時間に注意するのは違います。  AがBに送る時間  和  BがAに送る時間  はい、違います
すべての人に情報を伝えるのに一番時間がかかります。 
すべての人に一回お願いします。一番短絡的です。  maxtime配列を使って、一人当たりの一番長い時間を統計します。 一番短い人を探しています。
すべての人に伝えられないなら disjintを出力します
ACコード:
#include 
#include 
#include 
#include 
#include 
using namespace std;
const int inf = 99999999;
int n,m,maxn,head[105],vis[105],dis[105],b,c,allroad,maxtime[105];
struct r
{
    int e,d,nextroad;
}road[10000];
void add(int a,int b,int c)
{
    road[allroad].e = b;
    road[allroad].d = c;
    road[allroad].nextroad = head[a];
    head[a] = allroad;
}
void SPFA(int a)
{
    for(int i=1;i<=n;i++)
    {
        dis[i] = inf;
        vis[i] = 0;
    }
    dis[a] = 0;
    queue  q;
    while(!q.empty()) q.pop();
    q.push(a);
    vis[a] = 1;
    while(!q.empty())
    {
        int now = q.front();
        q.pop(); vis[now] = 0;
        for(int j=head[now] ; j!=-1 ; j=road[j].nextroad)
        {
            int to = road[j].e;
            int dd = road[j].d;
            if((dis[now]+dd)