#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. tabl-cell

    参考:http://www.cnblogs.com/StormSpirit/archive/2012/10/24/2736453.html 总结特点 多个并排的table-cell始终等高. 宽度可以 ...

  2. 周三面试Python开发,这几道Python面试题差点答错,Python面试题No7

    第1题:阅读下面的代码,默读出A0,A1至An的最终值. A0 = dict(zip(('a','b','c','d','e'),(1,2,3,4,5))) A1 = range(10) A2 = [ ...

  3. 小白安装Python环境详细步骤!

    昨天,有小伙伴向我反映,他对我说“你好像还没教过我安装Python的吧?”听到这句话,我不禁汗颜起来,我的确好像没太注意Python学习的基础了,一直发各种爬虫与初学者看不懂的代码,在此我要向我的读者 ...

  4. CentOS 7 设置开机自启动

    创建脚本:    #!/bin/bash    echo "hello!" # 启动虚拟环境    cd /data/env/crmenv/bin/    source activ ...

  5. [MVC]在练习MusicStore过程中问题实录

    1,问题描述:MVC在添加基于框架的控制器时,出现无法检索xxx的元数据 参考目录:http://www.cnblogs.com/0banana0/p/4050793.html#undefined 解 ...

  6. 软件测试人员遇到发现的bug不能重现怎么办?

    软件测试人员遇到发现的bug不能重现怎么办?   刚刚进入测试的童鞋们,想必都遇到过提出的bug,开发要求重现之后,但是在系统上已经重现不了的情况吧. 那么碰到这样的情况,不管开发还是测试都很纠结,开 ...

  7. ExtJS前端框架EXT弹出窗口事件

    https://blog.csdn.net/alsyuan/article/details/73240841 Ext.MessageBox.alert()Ext.MessageBox.alert()提 ...

  8. Food Delivery (区间DP)

    When we are focusing on solving problems, we usually prefer to stay in front of computers rather tha ...

  9. BZOJ 1022: [SHOI2008]小约翰的游戏John【anti-SG】

    Description 小约翰经常和他的哥哥玩一个非常有趣的游戏:桌子上有n堆石子,小约翰和他的哥哥轮流取石子,每个人取的时候,可以随意选择一堆石子,在这堆石子中取走任意多的石子,但不能一粒石子也不取 ...

  10. ACDream:1210:Chinese Girls' Amusement【水题】

    Chinese Girls' Amusement Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Oth ...