HDOJ5521(巧妙构建完全图)
Meeting
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 2415 Accepted Submission(s): 765
fences they were separated into different blocks. John's farm are divided into n blocks labelled from 1 to n.
Bessie lives in the first block while Elsie lives in the n-th one. They have a map of the farm
which shows that it takes they ti minutes to travel from a block in Ei to another block
in Ei where Ei (1≤i≤m) is a set of blocks. They want to know how soon they can meet each other
and which block should be chosen to have the meeting.
follow.
The first line of input contains n and m. 2≤n≤105. The following m lines describe the sets Ei (1≤i≤m). Each line will contain two integers ti(1≤ti≤109) and Si (Si>0) firstly. Then Si integer follows which are the labels of blocks in Ei. It is guaranteed that ∑mi=1Si≤106.
Otherwise, output two lines. The first line contains an integer, the time it takes for they to meet.
The second line contains the numbers of blocks where they meet. If there are multiple
optional blocks, output all of them in ascending order.
3 4
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
const int MAXN = ;
const int INF = 0x3f3f3f3f;
struct Edge{
int to, w, net;
}es[];
int head[MAXN], tot;
int n, m;
void addedge(int u, int v, int w)
{
es[tot].to = v;
es[tot].w = w;
es[tot].net = head[u];
head[u] = tot++;
}
void spfa(int src, int d[], bool vis[], int n)
{
for(int i = ; i <= n; i++)
{
d[i] = INF;
vis[i] =false;
}
d[src] = ;
queue<int> que;
que.push(src);
while(!que.empty())
{
int u = que.front(); que.pop();
vis[u] = false;
for(int i = head[u]; i != -; i = es[i].net)
{
Edge e = es[i];
if(d[e.to] > d[u] + e.w)
{
d[e.to] = d[u] + e.w;
if(!vis[e.to])
{
vis[e.to] = true;
que.push(e.to);
}
}
}
}
}
int d[][MAXN];
bool vis[MAXN];
int vec[MAXN], len;
int main()
{
int T;
scanf("%d", &T);
for(int cas = ; cas <= T; cas++)
{
memset(head, -, sizeof(head));
tot = ;
scanf("%d %d", &n ,&m);
int newN = n;
for(int i = ; i < m; i++)
{
int w, s;
scanf("%d %d", &w, &s);
//巧妙构图
int u = ++newN;
int v = ++newN;
addedge(u, v, w);
for(int j = ; j < s; j++)
{
int x;
scanf("%d", &x);
addedge(x, u, );
addedge(v, x, );
}
} spfa(, d[], vis, newN);
spfa(n, d[], vis, newN); int mn = INF;
for(int i = ; i <= n; i++)
{
int mx = max(d[][i], d[][i]);
if(mn > mx)
{
mn = mx;
}
}
if(mn == INF)
{
printf("Case #%d: Evil John\n", cas);
continue;
}
len = ;
for(int i = ; i <= n; i++)
{
if(max(d[][i], d[][i]) == mn)
{
vec[len++] = i;
}
}
printf("Case #%d: %d\n", cas, mn);
for(int i = ; i < len -; i++)
{
printf("%d ", vec[i]);
}
printf("%d\n", vec[len-]);
}
return ;
}
HDOJ5521(巧妙构建完全图)的更多相关文章
- 斯坦福第十一课:机器学习系统的设计(Machine Learning System Design)
11.1 首先要做什么 11.2 误差分析 11.3 类偏斜的误差度量 11.4 查全率和查准率之间的权衡 11.5 机器学习的数据 11.1 首先要做什么 在接下来的视频中,我将谈到机器 ...
- Machine Learning - 第6周(Advice for Applying Machine Learning、Machine Learning System Design)
In Week 6, you will be learning about systematically improving your learning algorithm. The videos f ...
- UVALive 4872 Underground Cables 最小生成树
题目链接: 题目 Underground Cables Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %ll ...
- 技巧:Linux 动态库与静态库制作及使用详解
技巧:Linux 动态库与静态库制作及使用详解 标准库的三种连接方式及静态库制作与使用方法 Linux 应用开发通常要考虑三个问题,即:1)在 Linux 应用程序开发过程中遇到过标准库链接在不同 L ...
- 【转载】NeurIPS 2018 | 腾讯AI Lab详解3大热点:模型压缩、机器学习及最优化算法
原文:NeurIPS 2018 | 腾讯AI Lab详解3大热点:模型压缩.机器学习及最优化算法 导读 AI领域顶会NeurIPS正在加拿大蒙特利尔举办.本文针对实验室关注的几个研究热点,模型压缩.自 ...
- Ng第十一课:机器学习系统的设计(Machine Learning System Design)
11.1 首先要做什么 11.2 误差分析 11.3 类偏斜的误差度量 11.4 查全率和查准率之间的权衡 11.5 机器学习的数据 11.1 首先要做什么 在接下来的视频将谈到机器学习系 ...
- 吴恩达-coursera-机器学习-week6
十.应用机器学习的建议(Advice for Applying Machine Learning) 10.1 决定下一步做什么 10.2 评估一个假设 10.3 模型选择和交叉验证集 10.4 诊断偏 ...
- C基础 工程中常用的排序
引言 - 从最简单的插入排序开始 很久很久以前, 也许都曾学过那些常用的排序算法. 那时候觉得计算机算法还是有点像数学. 可是脑海里常思考同类问题, 那有什么用呢(屌丝实践派对装逼学院派的深情鄙视). ...
- [CDH] Redis: Remote Dictionary Server
基本概念 一.安装 Redis: Remote Dictionary Server 远程字典服务 使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种 ...
随机推荐
- JS中,如何判断一个数是不是小数?如果是小数,如何判断它是几位小数??
<script type="text/javascript"> var x = 4.23323;//测试的数字 var y = String(x).in ...
- MySQL学习(二): 数据类型记录
整形: 浮点型: 日期时间:(使用较少,可能存在跨区域问题) 字符型: CHAR(M):定长,会将位数补充到M位 VARCHAR(M):非定长,最多到达M位 ENUM('v1','v2',...):从 ...
- 2017-2018-2 20165202 实验四《Android程序设计》实验报告
一.实验报告封面 二.实验内容 1.基于Android Studio开发简单的Android应用并部署测试; 2.了解Android.组件.布局管理器的使用: 3.掌握Android中事件处理机制. ...
- vue.js 源代码学习笔记 ----- 工具方法 lang
/* @flow */ // Object.freeze 使得这个对象不能增加属性, 修改属性, 这样就保证了这个对象在任何时候都是空的 export const emptyObject = Obje ...
- (转)MapReduce Design Patterns(chapter 3 (part 2))(六)
Top Ten Pattern Description Top ten模式跟前面的有很大的不同,跟输入数据大小无关,最终得到的记录数量是确定的.而在通用filtering中,输出的规模取决于输入数据. ...
- ORA-06512: at "SYS.XMLTYPE" 问题记录
执行SQL报错: SQL> SELECT COUNT(cl.enable_flg) FROM cont_ledger cl INNER JOIN project_project pp ON cl ...
- LitJson 不支持 float 类型数据
使用指引: 在 Unity 中使用 Best HTTP 插件的 LitJson 发送一些 Json格式数据给服务器,使用方式很简单: string jsonDataPost = JsonMapper. ...
- Unity3D 海水多线程渲染算法实现
笔者介绍:姜雪伟,IT公司技术合伙人,IT高级讲师,CSDN社区专家,特邀编辑,畅销书作者,已出版书籍:<手把手教你架构3D游戏引擎>电子工业出版社和<Unity3D实战核心技术详解 ...
- R︱Yandex的梯度提升CatBoost 算法(官方述:超越XGBoost/lightGBM/h2o)
俄罗斯搜索巨头 Yandex 昨日宣布开源 CatBoost ,这是一种支持类别特征,基于梯度提升决策树的机器学习方法. CatBoost 是由 Yandex 的研究人员和工程师开发的,是 Matri ...
- es6模块化开发
export导出 import导入 export {a:b} Export default {a:b}