题读了半天,意思是给出每个人的单向联系关系,求找到一个人使消息传播完全传播到所有人的所需时间最小值。本题数据太水了,没有disjoint也AC了。
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<sstream>
#define ll long long
using namespace std;
/**********************************************************/
const int N_MAX = 100+10;
const int INF = 0x00ffffff;
const double M_DBL_MAX = 1.7976931348623158e+308;
const double M_DBL_MIN = 2.2250738585072014e-308;
int maps[N_MAX][N_MAX];
int n;
/**********************************************************/
int min_2 (int x,int y) {return x<y?x:y;}
int max_2 (int x,int y) {return x>y?x:y;}
void swap (int& a, int& b){a^=b;b^=a;a^=b;}
void floyd ();
/**********************************************************/
int main()
{
//freopen ("in.txt","r",stdin);
while (scanf ("%d",&n)&&n)
{
int t,a,b;
for (int i=0;i<n;i++)
for (int j=0;j<n;j++)
maps[i][j]=(i==j?0:INF);
for (int i=0;i<n;i++){
scanf ("%d",&t);
for (int j=0;j<t;j++){
scanf ("%d%d",&a,&b);
maps[i][a-1]=b;
}
}
floyd ();
int id=-1,m=INF;
for (int i=0;i<n;i++){
int mmx=0;
for (int j=0;j<n;j++)
mmx=max_2 (mmx,maps[i][j]);
if (m>mmx){m=mmx;id=i;}
}
if (m<INF)
printf ("%d %d\n",id+1,m);
else printf ("disjoint\n");
}
return 0;
}
void floyd ()
{
for (int k=0;k<n;k++)
for (int i=0;i<n;i++)
for (int j=0;j<n;j++)
maps[i][j]=min_2 (maps[i][j],maps[i][k]+maps[k][j]);
}