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数据库,并提供多种 ...
随机推荐
- HTML通过jQuery传值赋值
网页传值很常见,如果通过动态网页传值,我们很容易实现.但是如果静态网页传值,这个就要找资料,方法或者询问大牛们了.这个原来还真的没有做过.今天一同事需要做这个类似的功能,应该是昨天了.本来是昨天写的, ...
- Prism 4 文档 ---第6章 高级MVVM场景
在上一章中描述了如何通过将UI,表现逻辑,业务逻辑分别放到三个单独的类中(View,View Model,Model),实现这些类之间的交互(通过数据绑定,命令以及数据验证接口)以及实现一个策 ...
- cf 915
t1:2分钟ac,简单模拟 t2:3发wa,最后再10分钟的时候过了 但是最后被hack了 t3:2发wa,最后还是被hack了 t4:拓扑排序 然后将一个点入度减一 然后是否能拓扑 t5:离散化+线 ...
- PHP实现登录功能DEMO
PHP实现登录的原理是什么呢?就是利用Session实现的,用户访问网站,系统会自动在服务器生成一个Session文件,这个Session可以用来存储用户的登录信息.好了,这是基本储备,我们下面来实现 ...
- 使用Apache的ab工具进行网站性能测试
Apache服务器自带了ab压力测试工具,可以用来测试网站性能,使用简单方便. ab 的用法是:ab [options] [http://]hostname[:port]/path 例如:ab -n ...
- C语言实现的矩阵乘法运算器
需求 编写程序模拟矩阵乘法,一个m*n的矩阵,乘以一个 n*m 的矩阵, 并且输出结果. STEP 1 矩阵乘法的计算 一个m行n列的矩阵与一个n行p列的矩阵可以相乘,得到的结果是一个m行p列的矩阵 ...
- Mac怎么安装Windows10
当前 Windows10 系统的预览版已经出来,对于新系统感兴趣的不只是使用 PC 电脑的用户,还有一些是当前正在使用 Mac 系统的用户.其实安装 Windows 10 与以前安装 Windows ...
- Kotlin Reference (七) Returns and Jumps
most from reference kotlin有三个结构跳跃表达式 return 默认情况下,从最近的封闭函数或匿名函数返回. break 跳出整个循环 continue 跳出本次循环,进行下一 ...
- CSDN博客积分规则
1.博客积分规则 博客积分是CSDN对用户努力的认可和奖励,也是衡量博客水平的重要标准.博客等级也将由博客积分唯一决定.积分规则具体如下: 每发布一篇原创或者翻译文章:可获得10分: 每发布一篇转载文 ...
- 全新Wijmo5中文学习指南正式上线
Wijmo 是一款使用 TypeScript 编写的新一代 JavaScript/HTML5 控件集.它秉承触控优先的设计理念,在全球率先支持 AngularJS,并且支持React.VueJS以及T ...