题意  在全部城市中找一个中心满足这个中心到全部公交网站距离的最大值最小 输出最小距离和满足最小距离编号最小的中心

最基础的BFS  对每一个公交网站BFS  dis[i]表示编号为i的点到全部公交网站距离的最大值  bfs全然部网站后  dis[i]最小的点就是要求的点咯

#include<cstdio>
#include<cstring>
#include<queue>
#include<set>
using namespace std;typedef set<int>::iterator it;
const int N = 10000;
int dis[N], tdis[N], link[N][12];
queue<int> q;
set<int> zone;void bfs(int o)
{memset(tdis, 0, sizeof(tdis));tdis[o] = 1;q.push(o);while(!q.empty()){int cur = q.front();q.pop();if(tdis[cur] > dis[cur]) dis[cur] = tdis[cur];for(int i = 1; i <= link[cur][0]; ++i){int j = link[cur][i];if(tdis[j] == 0)  q.push(j), tdis[j] = tdis[cur] + 1;}}
}int main()
{int cas, nz, nr, id, mz, mr, ans, t;scanf("%d", &cas);while(cas--){zone.clear();memset(dis, 0, sizeof(dis));scanf("%d%d", &nz, &nr);for(int i = 1; i <= nz; ++i){scanf("%d %d", &id, &mz);link[id][0] = mz;zone.insert(id);for(int i = 1; i <= mz; ++i)scanf("%d", &link[id][i]);}for(int i = 1; i <= nr; ++i){scanf("%d", &mr);for(int j = 1; j <= mr; ++j){scanf("%d", &t);bfs(t);}}it i = zone.begin();ans = *i;for(++i; i != zone.end(); ++i)if(dis[*i] < dis[ans]) ans = *i;printf("%d %d\n", dis[ans], ans);}return 0;
}

Bus Pass


Time Limit: 5 Seconds      Memory Limit: 32768 KB


You travel a lot by bus and the costs of all the seperate tickets are starting to add up.

Therefore you want to see if it might be advantageous for you to buy a bus pass.

The way the bus system works in your country (and also in the Netherlands) is as follows:

when you buy a bus pass, you have to indicate a center zone and a star value. You are allowed to travel freely in any zone which has a distance to your center zone which is less than your star value. For example, if you have a star value of one, you can only travel in your center zone. If you have a star value of two, you can also travel in all adjacent zones, et cetera.

You have a list of all bus trips you frequently make, and would like to determine the minimum star value you need to make all these trips using your buss pass. But this is not always an easy task. For example look at the following figure:


Here you want to be able to travel from A to B and from B to D. The best center zone is 7400, for which you only need a star value of 4. Note that you do not even visit this zone on your trips!

Input

On the first line an integert(1 <=t<= 100): the number of test cases. Then for each test case:

One line with two integersnz(2 <=nz<= 9 999) andnr(1 <=nr<= 10): the number of zones and the number of bus trips, respectively.

nz lines starting with two integers idi (1 <= idi <= 9 999) and mzi (1 <= mzi <= 10), a number identifying the i-th zone and the number of zones adjacent to it, followed by mzi integers: the numbers of the adjacent zones.

nr lines starting with one integer mri (1 <= mri <= 20), indicating the number of zones the ith bus trip visits, followed by mri integers: the numbers of the zones through which the bus passes in the order in which they are visited.

All zones are connected, either directly or via other zones.

Output

For each test case:

One line with two integers, the minimum star value and the id of a center zone which achieves this minimum star value. If there are multiple possibilities, choose the zone with the lowest number.

Sample Input

1
17 2
7400 6 7401 7402 7403 7404 7405 7406
7401 6 7412 7402 7400 7406 7410 7411
7402 5 7412 7403 7400 7401 7411
7403 6 7413 7414 7404 7400 7402 7412
7404 5 7403 7414 7415 7405 7400
7405 6 7404 7415 7407 7408 7406 7400
7406 7 7400 7405 7407 7408 7409 7410 7401
7407 4 7408 7406 7405 7415
7408 4 7409 7406 7405 7407
7409 3 7410 7406 7408
7410 4 7411 7401 7406 7409
7411 5 7416 7412 7402 7401 7410
7412 6 7416 7411 7401 7402 7403 7413
7413 3 7412 7403 7414
7414 3 7413 7403 7404
7415 3 7404 7405 7407
7416 2 7411 7412
5 7409 7408 7407 7405 7415
6 7415 7404 7414 7413 7412 7416

Sample Output

4 7400

ZOJ 2913 Bus Pass (近期的最远BFS HDU2377)相关推荐

  1. 致远a8-v5-6.0协同管理软件_高危漏洞利用预警:近期利用“致远OA任意文件写入漏洞”的攻击较多...

    概述腾讯御界高级威胁检测系统近期监测到"致远OA系统上的GetShell漏洞"在网上被频繁利用攻击政企客户. 对于存在漏洞的OA系统,攻击者无需任何权限,即可向服务器上传websh ...

  2. zoj 3864 Quiz for EXO-L(连通块 bfs)

    Quiz for EXO-L Time Limit: 2 Seconds      Memory Limit: 65536 KB Exo (Korean: 엑소; Chinese:爱咳嗽; often ...

  3. 【转载】图论 500题——主要为hdu/poj/zoj

    转自--http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  4. 【每日新闻】谷歌CEO皮查伊:AI会拯救人类,而不是摧毁 | 致远互联签约锤子科技

    每一个企业级的人  都置顶了 中国软件网 中国软件网  为你带来最新鲜的行业干货 小编点评 不能因为害怕风险 就避免开始 我们喜欢用现状去预测未来 其实未来远比预测精彩 期待AI 期待AI给我们带来的 ...

  5. NOIP 好题推荐(DP+搜索+图论)POJ ZOJ

    NOIP好题推荐(DP+搜索+图论)POJ ZOJ 1370 Gossiping (数论->模线性方程有无解的判断)+(图论->DFS)  1090 Chain ->格雷码和二进制码 ...

  6. ACM比赛经验、刷题记录及模板库总结(更新中)

    前言 本文所提及的部分题目代码,可以在我的Github上找到 第一部分 经验分享及感受 第二部分 刷题记录 一.基础算法&程序语言 //strlen()函数的复杂度是O(n)要小心 //截取字 ...

  7. 【HDOJ图论题集】【转】

    1 =============================以下是最小生成树+并查集====================================== 2 [HDU] 3 1213 How ...

  8. 一系列图论问题[转]

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  9. kk_想要学习的知识

    2018/4/27 计算几何 一.简介 计算几何属于ACM算法中比较冷门的分类,在省赛中只在前几年考察过,这两年还没有考过,而且和高精度计算一样,遇到题目主要靠套模板,因此对题意的理解至关重要,而且往 ...

最新文章

  1. html+css 百度首页练习
  2. Pycharm、Idea、Goland 官方汉化来了
  3. 官方原版美化修改版完美适配双端海洋cms模板
  4. WordPress美化_节日灯笼插件
  5. 这种反爬虫手段有点意思,看我破了它!
  6. 杭州滨江工作方案:将区块链等产业与“数字滨江”、“数字经济”紧密相连
  7. pycharm 中文_环境搭建:3.pycharm社区版安装配置
  8. [安卓学习]AndroidManifest.xml文件内容详解
  9. Applets 是什么 怎样使用 应用前景
  10. 安装SQL Server2012时出现启用Windows功能NetFx3时出错”的提示,导致无法安装成功
  11. 绿盟科技 linux漏洞,apache漏洞修复(绿盟科技漏洞)
  12. 一部手机即可轻松玩转抖音四大主流变现方式——匀思电商
  13. Android签名工具 AndroidMultitool使用方法
  14. JSLint中常见报错提示
  15. 蓝桥杯试题 基础练习 十六进制转八进制
  16. 程序员如何做SOHO一族接私单做呢?
  17. python多线程爬取妹子图
  18. 使用ajax传递数组
  19. H.264软件编码与硬件编码格式对比
  20. linux我的世界乱码,我的世界附魔台文字翻译成普通文字 附魔台文字乱码解决办法...

热门文章

  1. 人工智能开放平台建设火热,AI发展未来可期
  2. 分组卷积新进展,全自动学习的分组有哪些经典模型?
  3. 阿布扎比成立全球首所培养研究生的人工智能大学
  4. 学好人工智能,其实不难,从以下几点开始
  5. 金审系统与SAP接口
  6. 李彦宏:用“工程思维”做自动驾驶
  7. 科普|深度解析5G与未来天线技术
  8. ​IBM人工智能芯片的新进展
  9. 联合国2019数字经济报告
  10. 腾讯张正友:计算机视觉的三生三世