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数据库,并提供多种 ...
随机推荐
- Arison [JS]window.location获取url各项参数详解
https://www.cnblogs.com/Arison/p/5286368.html 对于这样一个URL代码如下 复制代码 http://www.php230.com :80/fisker/po ...
- easychm生成帮助文件时出现的目录导航乱码问题
将html生成帮助文件时出现乱码问题的主要原因是:文件编译格式的问题 (一般的网页都是utf-8格式的,将其改为GB2312就可以了):
- c# 处理js序列化时 datetime返回UTC格式的问题
using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using Syst ...
- CS231n课程笔记翻译3:线性分类笔记
译者注:本文智能单元首发,译自斯坦福CS231n课程笔记Linear Classification Note,课程教师Andrej Karpathy授权翻译.本篇教程由杜客翻译完成,巩子嘉和堃堃进行校 ...
- python基础(二)----数据类型
Python基础第二章 二进制 字符编码 基本数据类型-数字 基本数据类型-字符串 基本数据类型-列表 基本数据类型-元组 可变.不可变数据类型和hash 基本数据类型-字典 基本数据类型-集合 二进 ...
- kubeadm搭建kubernetes集群之一:构建标准化镜像
使用docker可以批量管理多个容器,但都是在同一台电脑内进行的,这在实际生产环境中是不够用的,如何突破单机的限制?让多个电脑上的容器可以像单机上的docker-compose.yml管理的那样方便呢 ...
- 自动化测试入门指南(3)-- 入门demo
按照 自动化测试入门指南(2)-- 环境搭建搭建好环境后,我们继续一步步实现一个简单的入门例子 Step0. 安装Firefox浏览器(http://pan.baidu.com/s/1c00bw8g中 ...
- BZOJ4550: 小奇的博弈(NIMK博弈& 组合数& DP)
4550: 小奇的博弈 Time Limit: 2 Sec Memory Limit: 256 MBSubmit: 159 Solved: 104[Submit][Status][Discuss] ...
- 【JPA 级联保存/级联删除】@OneToMany (双向) 一对多【转】
[http://blog.sina.com.cn/s/blog_625d79410101dbdd.html] 看过前两篇帮助文档 [JPA] @OneToOne 单向 和 [JPA]@OneToO ...
- threejs Object的点击(鼠标)事件(获取点击事件的object)
objects=[]; raycaster = new THREE.Raycaster(); mouse = new THREE.Vector2(); //监听全局点击事件,通过ray检测选中哪一个o ...