[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】iOS裁剪或者压缩后出现的白边问题
只需要将所有的CGFloat转化为NSInteger即可 func imageScaleSize(newSize: CGSize) -> UIImage{ let width = NSInteg ...
- Python 图片转字符画
Python 图片转字符画 一.课程介绍 1. 课程来源 原创 2. 内容简介 本课程讲述怎样使用 Python 将图片转为字符画 3. 前置课程 Python编程语言 Linux 基础入门(新版) ...
- 201421123042 《Java程序设计》第9周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 2. 书面作业 本次作业题集集合 1. List中指定元素的删除(题集题目) 1.1 实验总结.并回答:列举至 ...
- 51Nod P1100 斜率最大
传送门: https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1100 由于2 <= N <= 10000, 所以 ...
- bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪
http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...
- 如何深入系统的学习一门编程语言——python自学笔记
前言 最早接触python的时候,他并没有现在这么火,我也没把他太当回事,那时候我对python的印象就是给运维人员使用的一门很古老的语言,显然随着tensorflow(以下简称tf)的兴起,pyth ...
- YML(2)yml 语法
YAML 语法 来源:yaml 这个页面提供一个正确的 YAML 语法的基本概述, 它被用来描述一个 playbooks(我们的配置管理语言). 我们使用 YAML 是因为它像 XML 或 JSON ...
- maven快速下载jar镜像
<!--国内镜像--><mirror> <id>CN</id> <name>OSChina Central</name> ...
- UIView圆角设置
对于UIview的圆角设置最简单的就是layer的两个属性分别是cornerRadius和masksToBounds,但是对于设置其中某一个角为圆角的时候需要使用贝塞尔曲线 UIView *aView ...
- Linux磁盘分区-rpm-yum
一.磁盘分区 1.开启Linux系统前添加一块大小为15G的SCSI硬盘 2.开启系统,右击桌面,打开终端 3.为新加的硬盘分区,一个主分区大小为5G,剩余空间给扩展分区,在扩展分区上划分1个逻辑分区 ...