记录编号 |
581137 |
评测结果 |
AAAAAAAA |
题目名称 |
双服务点设置 |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.000 s |
提交时间 |
2023-07-29 15:44:11 |
内存使用 |
0.74 MiB |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
const int N = 110,M = 10010;
int n,m;
struct made{
int ver,ed,nx;
}e[M];
int hd[M],tot,v[N],d[N],dj[N][N];
int s1,s2,ans = INT_MAX;
void add_(int x,int y,int z){
tot++;
e[tot].ver = y,e[tot].ed = z,e[tot].nx = hd[x],hd[x] = tot;
}
bool find(int x,int y,int z){
for(int i = hd[x];i;i = e[i].nx){
if(e[i].ver == y){
e[i].ed = z;
return 1;
}
}
return 0;
}
void init(){
scanf("%d%d",&n,&m);
for(int i = 1;i <= m;i++){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
x++,y++;//以0至n-1为编号改为1至n
if(find(x,y,z));
else add_(x,y,z);
if(find(y,x,z));
else add_(y,x,z);
}
}//如果有重边,以最新输入的为准
void dij(int x){
memset(v,0,sizeof(v));
memset(d,0x3f,sizeof(d));
priority_queue<P,vector<P>,greater<P> >q;
d[x] = 0;
q.push(make_pair(d[x],x));
while(!q.empty()){
int x = q.top().second;q.pop();
if(v[x])continue;
v[x] = 1;
for(int i = hd[x];i;i = e[i].nx){
int y = e[i].ver,z = e[i].ed;
if(d[x] + z < d[y]){
d[y] = d[x] + z;
q.push(make_pair(d[y],y));
}
}
}
}//dijkstra
int main(){
freopen("djsb.in","r",stdin);
freopen("djsb.out","w",stdout);
init();
for(int i = 1;i <= n;i++){
dij(i);
int s = 0;
for(int j = 1;j <= n;j++){
dj[i][j] = d[j];
}
}
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
if(i == j)continue;//两个服务点不能相同
int s = 0;
for(int k = 1;k <= n;k++){
s = max(s,min(dj[i][k],dj[j][k]));
}
if(s < ans){
s1 = i,s2 = j,ans = s;
}
}
}//枚举两个服务点
printf("%d %d\n",min(s1,s2)-1,max(s1,s2)-1);//因为改了编号素养要减1
return 0;
}