记录编号 |
92469 |
评测结果 |
AAAAAAAA |
题目名称 |
服务点设置 |
最终得分 |
100 |
用户昵称 |
雪狼 |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.014 s |
提交时间 |
2014-03-21 10:08:28 |
内存使用 |
0.28 MiB |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#define maxn 100+10
#define INF ~0U>>2
#define REP(i,a,b) for(int i=a;i!=b+1;++i)
using namespace std;
struct edge{
int from,to,dis;
};
int n,m,s,t;
vector<edge>E;
vector<int>G[maxn];
int d[maxn];
bool vis[maxn];
void addedge(int from,int to,int dis){
E.push_back((edge){from,to,dis});
E.push_back((edge){to,from,dis});
int s=E.size();
G[from].push_back(s-2);
G[to].push_back(s-1);
}
int SPFA(int s){
REP(i,1,n)d[i]=INF,vis[i]=0;
d[s]=0,vis[s]=1;
queue<int>Q;
Q.push(s);
while(!Q.empty()){
int x=Q.front();
Q.pop();vis[x]=0;
REP(i,0,G[x].size()-1){
edge &e=E[G[x][i]];
if(d[e.to]>d[e.from]+e.dis){
d[e.to]=d[e.from]+e.dis;
if(!vis[e.to]){
Q.push(e.to);
vis[e.to]=1;
}
}
}
}
int cnt=0;
REP(i,1,n)if(d[i]>cnt)cnt=d[i];
return cnt;
}
void read(){
int a,b,c;
int map[maxn][maxn];
scanf("%d%d",&n,&m);
REP(i,1,n)REP(j,1,n)map[i][j]=INF;
REP(i,1,m){
scanf("%d%d%d",&a,&b,&c);
map[a+1][b+1]=map[b+1][a+1]=c;
}
REP(i,1,n-1)REP(j,i+1,n)if(map[i][j]!=INF)
addedge(i,j,map[i][j]);
}
void work(){
int ans=INF,ans_i;
REP(i,1,n){
int t=SPFA(i);
if(t<ans)ans=t,ans_i=i;
//cout<<t<<' ';
}
printf("%d\n",ans_i-1);
}
void setIO(string s){
string in=s+".in",out=s+".out";
freopen(in.c_str(),"r",stdin);
freopen(out.c_str(),"w",stdout);
}
int main(){
setIO("djsa");
read();
work();
return 0;
}