[SCOI 2012]滑雪与时间胶囊
Description
Input
Output
Sample Input
3 2 1
1 2 1
2 3 1
1 3 10
Sample Output
HINT
【数据范围】
对于30%的数据,保证 1<=N<=2000
对于100%的数据,保证 1<=N<=100000
对于所有的数据,保证 1<=M<=1000000,1<=Hi<=1000000000,1<=Ki<=1000000000。
题解
对于第一问,我们直接遍历一遍就好了。
对于第二问,把第一问中的边取出。结点具有层次性,且不具有环。把边先按终点高度排序为第一关键字(从大到小),边长为第二关键字排序(从大到小)之后,就会保证优先到高点,同高点之间选最小边。
//It is made by Awson on 2017.10.26
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define link LINK
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Abs(a) ((a) < 0 ? (-(a)) : (a))
using namespace std;
const int N = 1e5;
const int M = 1e6; int n, m, h[N+], u, v, w, ans1;
LL ans2;
struct tt {
int to, cost, next;
}edge[(M<<)+];
struct ss {
int from, to, cost;
bool operator < (const ss &b) const{
return h[to] == h[b.to] ? cost < b.cost : h[to] > h[b.to];
}
}link[(M<<)+];
int path[N+], top;
bool vis[N+];
int st[N+]; int find(int r) {
return st[r] ? st[r] = find(st[r]) : r;
}
void bfs() {
queue<int>Q;
while (!Q.empty()) Q.pop();
Q.push(); vis[] = ;
while (!Q.empty()) {
int u = Q.front(); ans1++; Q.pop();
for (int i = path[u]; i; i = edge[i].next)
if (!vis[edge[i].to]) {
Q.push(edge[i].to); vis[edge[i].to] = ;
}
}
}
void add(int u, int v, int c) {
edge[++top].to = v;
edge[top].cost = c;
edge[top].next = path[u];
path[u] = top;
}
void Kruskal() {
int cnt = ;
for (int u = ; u <= n; u++)
for (int j = path[u]; j; j = edge[j].next)
if (vis[u] && vis[edge[j].to])
link[++cnt].from = u, link[cnt].to = edge[j].to, link[cnt].cost = edge[j].cost;
sort(link+, link++cnt);
for (int i = ; i <= cnt; i++) {
int u = link[i].from, v = link[i].to, c = link[i].cost;
int p = find(u), q = find(v);
if (p != q) {
st[p] = q; ans2 += c;
}
}
}
void work() {
scanf("%d%d", &n, &m);
for (int i = ; i <= n; i++) scanf("%d", &h[i]);
for (int i = ; i <= m; i++) {
scanf("%d%d%d", &u, &v, &w);
if (h[u] >= h[v]) add(u, v, w);
if (h[v] >= h[u]) add(v, u, w);
}
bfs();
Kruskal();
printf("%d %lld\n", ans1, ans2);
}
int main() {
work();
return ;
}
[SCOI 2012]滑雪与时间胶囊的更多相关文章
- bzoj 2753 [SCOI 2012] 滑雪与时间胶囊 - Prim
题目传送门 传送点I 传送点II 题目大意 给定一个有$n$个点$m$条边的图,每个点有一个高度$h_{i}$,能从$u$经过一条边到达$v$,当且仅当存在一条边是$(u, v)$或$(v, u)$, ...
- 【最小树形图(奇怪的kruskal)】【SCOI 2012】【bzoj 2753】滑雪与时间胶囊
2753: [SCOI2012]滑雪与时间胶囊 Time Limit: 50 Sec Memory Limit: 128 MB Submit: 1621 Solved: 570 Description ...
- Bzoj2753 [SCOI2012]滑雪与时间胶囊
2753: [SCOI2012]滑雪与时间胶囊 Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 2282 Solved: 796 Descriptio ...
- 【BZOJ】【2753】【SCOI2012】滑雪与时间胶囊
Kruskal/最小树形图 然而蒟蒻并不会做这题>_> 本来以为是有向图最小生成树,即最小树形图,但这数据范围有点…… 膜拜了zyf的题解:http://www.cnblogs.com/z ...
- BZOJ 2753 [SCOI2012] 滑雪和时间胶囊 最小生成树
题目链接: 题目 2753: [SCOI2012]滑雪与时间胶囊 Time Limit: 50 Sec Memory Limit: 128 MB 问题描述 a180285非常喜欢滑雪.他来到一座雪山, ...
- bzoj 2753: [SCOI2012]滑雪与时间胶囊 -- 最小生成树
2753: [SCOI2012]滑雪与时间胶囊 Time Limit: 50 Sec Memory Limit: 128 MB Description a180285非常喜欢滑雪.他来到一座雪山,这 ...
- CDOJ 42/BZOJ 2753 滑雪与时间胶囊 kruskal
2753: [SCOI2012]滑雪与时间胶囊 Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 1376 Solved: 487[Submit][St ...
- 【BZOJ 2753】 2753: [SCOI2012]滑雪与时间胶囊 (分层最小树形图,MST)
2753: [SCOI2012]滑雪与时间胶囊 Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 2457 Solved: 859 Descriptio ...
- BZOJ2753 SCOI2012 滑雪与时间胶囊 【最小生成树】*
BZOJ2753 SCOI2012 滑雪与时间胶囊 Description a180285非常喜欢滑雪.他来到一座雪山,这里分布着M条供滑行的轨道和N个轨道之间的交点(同时也是景点),而且每个景点都有 ...
随机推荐
- swift 创建九宫格在后面加按钮
项目中的需求是前面图片,在图片最后面始终有按钮如图 图片 let space:CGFloat = 10 for i in 0..model.count{ let itemWidth:CGFloat = ...
- JavaScript(第二十二天)【动态加载js和css】
学习要点: 1.元素位置 2.动态脚本 3.动态样式 本章主要讲解上一章剩余的获取位置的DOM方法.动态加载脚本和样式. 一.元素位置 上一章已经通过几组属性可以获取元素所需的位置,那么这节课补充 ...
- Python 图片转字符画
Python 图片转字符画 一.课程介绍 1. 课程来源 原创 2. 内容简介 本课程讲述怎样使用 Python 将图片转为字符画 3. 前置课程 Python编程语言 Linux 基础入门(新版) ...
- nyoj 擅长排列的小名II
擅长排列的小明 II 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 小明十分聪明,而且十分擅长排列计算. 有一天小明心血来潮想考考你,他给了你一个 ...
- Python之旅.第二章数据类型 3.19/3.20/3.21/3.22/3.23
一.数字类型 1.int类型: 基本使用: 用途:用于年龄,手机号,身份证号: 定义: age=18: 常用操作+内置方法: 正常的运算赋值: 进制转换: print(bin(3)); 把十进制3转换 ...
- maven入门(9)Maven常用命令
Maven常用命令 清理 clean编译 compile打包 package安装 install跳过测试 clean package -Dmaven.test.skip=true
- GIT入门笔记(20)- git 开发提交代码过程梳理
git开发提交流程新项目开发,可以直接往master上提交老项目维护,可以在分支上修改提交,多次add和commit之后,也可以用pull合并主干和本地master,解决冲突后再push 1.检出代码 ...
- C#制作ActiveX插件
首先新建项目--->类库,取名:ActiveXDemo 右键项目属性:应用属性==>程序集信息=>使程序集Com可见, 生成==>输出==>为com互操作注册 新建接口类 ...
- Python之Scrapy爬虫框架 入门实例(一)
一.开发环境 1.安装 scrapy 2.安装 python2.7 3.安装编辑器 PyCharm 二.创建scrapy项目pachong 1.在命令行输入命令:scrapy startproject ...
- [LuoguP1113] 杂物 - 拓扑排序
其实只是纪念下第一篇洛谷题解? Description John的农场在给奶牛挤奶前有很多杂务要完成,每一项杂务都需要一定的时间来完成它.比如:他们要将奶牛集合起来,将他们赶进牛棚,为奶牛清洗乳房以及 ...