#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std; typedef long long LL; #define N 1000010 struct edge
{
LL to,next;
}e[N<<1];
LL head[N<<1];
LL cnt; struct Node
{
LL x,y,z;
}a[N<<1]; LL n,m;
LL x,y,z;
LL tot,ans; LL fa[N],vis[N],q[N]; LL h[N]; int find(LL x)
{
return fa[x]==x ? x : fa[x]=find(fa[x]);
} void link(LL x,LL y,LL z)
{
e[++cnt]=(edge){y,head[x]};
head[x]=cnt;
a[cnt]=(Node){x,y,z};
} int cmp(Node x,Node y)
{
return h[x.y]>h[y.y] || (h[x.y]==h[y.y] && x.z<y.z);
} void bfs()
{
queue<LL>q;
q.push(1);
vis[1]=1;
while (!q.empty())
{
LL now=q.front();
q.pop();
for (LL i=head[now];i;i=e[i].next)
{
LL t=e[i].to;
if (!vis[t])
{
q.push(t);
vis[t]=1;
tot++;
}
}
}
} int main()
{
scanf("%lld%lld",&n,&m);
for (LL i=1;i<=n;i++)
scanf("%lld",&h[i]);
for (LL i=1;i<=m;i++)
{
scanf("%lld%lld%lld",&x,&y,&z);
if (h[x]>=h[y])
link(x,y,z);
if (h[x]<=h[y])
link(y,x,z);
}
bfs();
printf("%lld ",tot+1);
for (LL i=1;i<=n;i++)
fa[i]=i;
sort(a+1,a+cnt+1,cmp);
for (LL i=1;i<=cnt;i++)
{
x=a[i].x;
y=a[i].y;
if (!vis[x] || !vis[y])
continue;
LL r1=find(x),r2=find(y);
if (r1!=r2)
fa[r1]=r2,ans+=a[i].z;
}
printf("%lld\n",ans);
return 0;
}

  

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
 
typedef long long LL;
 
#define N 1000010
 
struct edge
{
    LL to,next;
}e[N<<1];
LL head[N<<1];
LL cnt;
 
struct Node
{
    LL x,y,z;
}a[N<<1];
 
LL n,m;
LL x,y,z;
LL tot,ans;
 
LL fa[N],vis[N],q[N];
 
LL h[N];
 
int find(LL x)
{
    return fa[x]==x ? x : fa[x]=find(fa[x]);
}
 
void link(LL x,LL y,LL z)
{
    e[++cnt]=(edge){y,head[x]};
    head[x]=cnt;
    a[cnt]=(Node){x,y,z};
}
 
int cmp(Node x,Node y)
{
    return h[x.y]>h[y.y] || (h[x.y]==h[y.y] && x.z<y.z);
}
 
void bfs()
{
    queue<LL>q;
    q.push(1);
    vis[1]=1;
    while (!q.empty())
    {
        LL now=q.front();
        q.pop();
        for (LL i=head[now];i;i=e[i].next)
        {
            LL t=e[i].to;
            if (!vis[t])
            {
                q.push(t);
                vis[t]=1;
                tot++;
            }
        }
    }
}
 
int main()
{
    scanf("%lld%lld",&n,&m);
    for (LL i=1;i<=n;i++)
        scanf("%lld",&h[i]);
    for (LL i=1;i<=m;i++)
    {
        scanf("%lld%lld%lld",&x,&y,&z);
        if (h[x]>=h[y])
            link(x,y,z);
        if (h[x]<=h[y])
            link(y,x,z);
    }
    bfs();
    printf("%lld ",tot+1);
    for (LL i=1;i<=n;i++)
        fa[i]=i;
    sort(a+1,a+cnt+1,cmp);
    for (LL i=1;i<=cnt;i++)
    {
        x=a[i].x;
        y=a[i].y;
        if (!vis[x] || !vis[y])
            continue;
        LL r1=find(x),r2=find(y);
        if (r1!=r2)
            fa[r1]=r2,ans+=a[i].z;
    }
    printf("%lld\n",ans);
    return 0;
}

【bzoj2753】[SCOI2012]滑雪与时间胶囊的更多相关文章

  1. BZOJ2753 SCOI2012 滑雪与时间胶囊 【最小生成树】*

    BZOJ2753 SCOI2012 滑雪与时间胶囊 Description a180285非常喜欢滑雪.他来到一座雪山,这里分布着M条供滑行的轨道和N个轨道之间的交点(同时也是景点),而且每个景点都有 ...

  2. Bzoj2753 [SCOI2012]滑雪与时间胶囊

    2753: [SCOI2012]滑雪与时间胶囊 Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 2282  Solved: 796 Descriptio ...

  3. bzoj2753[SCOI2012]滑雪与时间胶囊 最小生成树

    Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 2843  Solved: 993[Submit][Status][Discuss] Descripti ...

  4. BZOJ2753 SCOI2012滑雪与时间胶囊(最小生成树)

    首先显然可以把所有能到的点拎出来建个新图,这样第一问也就做好了. 剩下的部分似乎是一个裸的最小树形图.但显然这个东西是没什么学的必要的并且不太能跑过去. 考虑建出来的图有什么性质.可以发现如果没有高度 ...

  5. BZOJ2753 [SCOI2012]滑雪与时间胶囊 【kruskal】

    题目链接 BZOJ2753 题解 完了我连\(kruskal\)裸题都做不出来了.. 题目是求最小树形图,即有向图最小生成树 我们不能直接上\(kruskal\),而要保证先加入前面的点, 所以我们排 ...

  6. [BZOJ2753][SCOI2012]滑雪与时间胶囊(特殊的有向树形图)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2753 分析: 第一问:直接BFS扩展知道无法扩展 第二问: 看似就是最小树形图啊= = ...

  7. 2019.01.17 bzoj2753: [SCOI2012]滑雪与时间胶囊(最小生成树)

    传送门 最小生成树菜题. 题意:给出一些有向边,问有向的最小生成树. 思路:先dfsdfsdfs一把所有有用的边都存起来,然后按终点点权为第一关键字,边权为第二关键字给边排序保证最小生成树的合法性,排 ...

  8. BZOJ 2753 [SCOI2012] 滑雪和时间胶囊 最小生成树

    题目链接: 题目 2753: [SCOI2012]滑雪与时间胶囊 Time Limit: 50 Sec Memory Limit: 128 MB 问题描述 a180285非常喜欢滑雪.他来到一座雪山, ...

  9. bzoj 2753: [SCOI2012]滑雪与时间胶囊 -- 最小生成树

    2753: [SCOI2012]滑雪与时间胶囊 Time Limit: 50 Sec  Memory Limit: 128 MB Description a180285非常喜欢滑雪.他来到一座雪山,这 ...

  10. 【BZOJ 2753】 2753: [SCOI2012]滑雪与时间胶囊 (分层最小树形图,MST)

    2753: [SCOI2012]滑雪与时间胶囊 Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 2457  Solved: 859 Descriptio ...

随机推荐

  1. 第六天,字典Dictionary

    字典(Dictionary)在Python中是一种可变的容器模型,它是通过一组键(key)值(value)对组成,这种结构类型通常也被称为映射,或者叫关联数组,也有叫哈希表的.每个key-value之 ...

  2. H5在ios弹窗状态下调起输入法后关闭输入法页面元素错位解决办法

    最近开发移动端,有个需求:点击退款弹出文本框和发送短信按钮,输入手机号码和验证码确定退款. 发现安卓手机没毛病,但是在ios手机上点击文本框调起输入法,此时点击完成或者关闭输入法就无法正常操作了,肉眼 ...

  3. 【01】sass基础信息:

    [01]基础信息:   2016年4月16日   最新版本:3.4.22   官网:http://sass-lang.com/(下图)       CSStoSCSS 网站:http://css2sa ...

  4. JavaScript验证密码强度

    JavaScript的方法: <script type="text/javascript"> window.onload = function () { documen ...

  5. 【转】Quartz.NET

    原文链接:http://www.cnblogs.com/tommyli/archive/2009/02/09/1386644.html Quartz.NET是一个开源的作业调度框架,是OpenSymp ...

  6. python出现'module' object is not callable错误

  7. 什么是Istio

    本文主要是对Istio Prelim 1.0(https://preliminary.istio.io/docs/)的翻译 Istio:一种开放式平台,用于连接,管理和保护微服务. Istio提供了一 ...

  8. MacOS & iOS

    MacOS & iOS https://github.com/qinjx/30min_guides/blob/master/ios.md https://www.cnblogs.com/xgq ...

  9. VS Code 列编辑功能说明

    新版本v1.13.1或者附近的版本中的列编辑功能已经调整. 一.多光标插入功能 Alt+鼠标左键,添加多光标输入 二.自由多行选择 Alt键+鼠标左键拖动选择各行的部分内容 三.列选择 Shift+A ...

  10. Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'

    Spring Security :HTTP Status 403-Invalid CSRF Token 'null' was found on the request parameter '_csrf ...