HDU4460
#include <iostream>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdio>
#include <map>
using namespace std;
#define MAX 9999999
int dis[+][+];
int vis[+];
string name[+];
int n;
map<string,int> mymap;
vector<int> vec[+];
void spfa(int i)
{
memset(vis,,sizeof(vis));
dis[i][i]=;
vis[i]=;
queue<int> q;
q.push(i);
while(!q.empty())
{
int temp=q.front();
q.pop();
for(int j=;j<vec[temp].size();j++)
{
int to=vec[temp][j];
if(vis[to])
continue;
dis[i][to]=dis[i][temp]+;
q.push(to);
vis[to]=;
}
}
}
int main()
{
int T;
while(cin>>n,n)
{
for(int i=;i<n;i++)
{
for(int j=i+;j<n;j++)
{
dis[i][j]=dis[j][i]=MAX;
}
}
for(int i=;i<n;i++)
vec[i].clear();
int cou=;
string str;
for(int i=;i<n;i++)
{
cin>>str;
mymap[str]=cou++;
}
int m;
cin>>m;
string str1,str2;
for(int i=;i<m;i++)
{
cin>>str1>>str2;
int t1=mymap[str1];
int t2=mymap[str2];
vec[t1].push_back(t2);
vec[t2].push_back(t1);
}
for(int i=;i<n;i++)
{
spfa(i);
}
int ans=;
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
ans=max(ans,dis[i][j]);
}
}
if(ans==MAX)
cout<<-<<endl;
else
cout<<ans<<endl;
}
return ; }
HDU4460的更多相关文章
- HDU-4460 Friend Chains(BFS&权为1所有最短路的最大值)
题目: For a group of people, there is an idea that everyone is equals to or less than 6 steps away fro ...
- hdu4460 Friend Chains(记忆化广度优先搜索)
题意: 任意两点间最短路中的最长距离. 思路: BFS遍历每个点能到达的最远距离. Tips: vector的clear要与resize联用. #include <bits/stdc++.h&g ...
随机推荐
- xml模块学习
import xml.etree.ElementTree as ET tree = ET.parse("xmltest.xml") root = tree.getroot() pr ...
- RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa
两个python,一个是本机自带的,一个是anaconda.先前呢,用自带的安装了Opencv,由于自带的python,对应的numpy版本是13, 而anaconda对应的版本是12,导致impor ...
- redis 配置文件解释 以及集群部署
redis是一款开源的.高性能的键-值存储(key-value store),和memcached类似,redis常被称作是一款key-value内存存储系统或者内存数据库,同时由于它支持丰富的数据结 ...
- 颜色空间之CIE2000色差公式
CIEDE2000色差公式 为了进一步改善工业色差评价的视觉一致性,CIE专门成立了工业色差评价的色相和明度相关修正技术委员会TC1-47(Hue and Lightness Dependent ...
- MySQL复制相关技术的简单总结
MySQL有很多种复制,至少从概念上来看,传统的主从复制,半同步复制,GTID复制,多线程复制,以及组复制(MGR).咋一看起来很多,各种各样的复制,其实从原理上看,各种复制的原理并无太大的异同.每一 ...
- css预处理器:Sass LASS Stylus
语法 Sass h1 { color: #0982C1; } h1 color: #0982c1 LESS h1 { color: #0982C1; } Stylus /* style.styl */ ...
- select 自匹配问题
原生js给select赋值或者vue绑定数据,会自匹配下拉选项的value或者key,从而显示对应的label或者对应的option的html eg: 原生: <select name=&quo ...
- POJOの説明
参考URL: https://baike.baidu.com/item/POJO/3311958?fr=aladdin https://wenku.baidu.com/view/eba89bbcf12 ...
- 【c】多级指针
一.一级指针 1.int *p,*p2; p是变量名,*表明是指针,指针指向地址. 在定义时初始化,如int *p_2 = &b; //定义一个指针,指针指向一个地址 先定义再初始化,如int ...
- BootStrap布局组件
BootStrap字体图标(Glyphicons) BootStrap下拉菜单:下拉菜单是可以切换的,是以列表格式显示链接的上下文菜单. 类 描述 .dropdown 指定下拉菜单 .dropdown ...