当前位置:网站首页>[ybtoj advanced training guide] maximum separation [hash] [Floyd]
[ybtoj advanced training guide] maximum separation [hash] [Floyd]
2022-06-28 09:14:00 【VL——MOESR】

Ideas :
Just use your name hash save , When you meet a new one, open one , then Floyd
This is used here. map
c o d e code code
#include<iostream>
#include<map>
#include<cstring>
#include<cstdio>
using namespace std;
int n, m;
int dis[55][55];
map<string, int> a;
int main()
{
int t=0;
while(1)
{
t++;
scanf("%d%d", &n, &m);
if(n==m&&n==0)
break;
a.clear();
memset(dis, 0x3f3f3f3f3f, sizeof(dis));
for(int i=1; i<=n; i++) dis[i][i]=0;
for(int i=1, j=0; i<=m; i++)
{
string s1, s2;
cin>>s1>>s2;
if(a[s1]==0)
a[s1]=++j;
if(a[s2]==0)
a[s2]=++j;
dis[a[s1]][a[s2]]=dis[a[s2]][a[s1]]=1;
}
for(int k=1; k<=n; k++)
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
if(dis[i][j]>dis[i][k]+dis[k][j])
dis[i][j]=dis[i][k]+dis[k][j];
int ans=0;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
ans=max(ans, dis[i][j]);
if(ans==1061109567)
printf("Network %d: DISCONNECTED\n", t);
else printf("Network %d: %d\n", t, ans);
}
return 0;
}
/* 4 4 Ashok Kiyoshi Ursala Chun Ursala Kiyoshi Kiyoshi Chun */
边栏推荐
- How to solve the problem of port number occupation
- Power data
- Error: `brew cask` is no longer a `brew` command. Use `brew <command> --cask` instead.
- How to implement two factor authentication MFA based on RADIUS protocol?
- 1181:整数奇偶排序
- 用Pytorch搭建第一個神經網絡且進行優化
- 华泰证券网上开户安全吗 办理流程是什么
- spark的资源调度和任务调度
- Fire safety hazards
- DEJA_ Vu3d - 052 of cesium feature set - Simulation of satellite orbit (high altitude) effect
猜你喜欢

Discussion on the improvement and application of the prepayment system in the management of electricity charge and price

Application of energy management system in iron and steel enterprises

Calculation of stock purchase and sale expenses

STL -- binder

基于宽表的数据建模

Rich text - Test Case

Import and export of a single collection in postman

How to solve the problem of high concurrency and seckill

containerd1.5.5的安装

Prototype chain JS
随机推荐
DEJA_VU3D - Cesium功能集 之 052-模拟卫星轨道(高空)效果
Guangzhou: new financial activities and new opportunities for enterprises
买卖股票费用计算
How to implement two factor authentication MFA based on RADIUS protocol?
Test cases for learning the basic content of software testing (II)
A - Bi-shoe and Phi-shoe
1180:分数线划定/P1068 [NOIP2009 普及组] 分数线划定
如何实现基于 RADIUS 协议的双因子认证 MFA?
104. maximum depth of binary tree
静态代码块永远先执行? 格局小了!!!
SQL injection file read / write
【大案例】学成在线网站
When the interviewer asks you to write binarysort in two ways
Assertions used in the interface automation platform
Apache Doris 成为 Apache 顶级项目
1182: effets de la photo de groupe
rman備份報ORA-19809 ORA-19804
Learn how Alibaba manages the data indicator system
1180: fractional line delimitation /p1068 [noip2009 popularization group] fractional line delimitation
Android studio interview preparation