#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. 如何将表的行数赋值给变量(MySQL)

    delimiter $$ drop procedure if exists test_at $$ create definer=root@localhost procedure test_at() b ...

  2. FTS5与DIY

    此文已由作者王荣涛授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. FTS5简介 前文已经介绍了FTS3/FTS4,本文着重介绍它们的继任者FTS5. FTS5是在SQLite ...

  3. ZOJ3860-Find the Spy

    Find the Spy Time Limit: 2 Seconds      Memory Limit: 65536 KB Whoooa! There is a spy in Marjar Univ ...

  4. 【贪心】codeforces B. Heidi and Library (medium)

    http://codeforces.com/contest/802/problem/B [题意] 有一个图书馆,刚开始没有书,最多可容纳k本书:有n天,每天会有人借一本书,当天归还:如果图书馆有这个本 ...

  5. 把disable maven nature后的项目,恢复菜单呈现出来(Convert to Maven Project)

    把disable maven nature后的项目,恢复菜单呈现出来(Convert to Maven Project) 有的时候需求把disable maven nature后的项目,再转换为mav ...

  6. 【POJ3254】Corn Fields(状压DP)

    题意: 一个M x N矩阵里有很多格子,每个格子有两种状态,可以放牧和不可以放牧,可以放牧用1表示,否则用0表示,在这块牧场放牛,要求两个相邻的方格不能同时放牛,即牛与牛不能相邻.问有多少种放牛方案( ...

  7. ASP.NET程序开发中经典常用的三十三种代码实例[确实有用]

    原文发布时间为:2008-11-10 -- 来源于本人的百度文章 [由搬家工具导入] ASP.NET程序开发中经典常用的三十三种代码实例:1. 打开新的窗口并传送参数: 传送参数:response.w ...

  8. ES6__变量的解构赋值

    /* 变量的解构赋值 */ /* 基本概念 : 本质上就是一种匹配模式,只要等号两边的模式相同,那么左边的变量就可以被赋予对应的值. 结构赋值主要分为: 1. 数组的解构赋值 2. 对象的结构赋值 3 ...

  9. C. Wilbur and Points---cf596C

    http://codeforces.com/problemset/problem/596/C 题目大意:  给你n个数对  确保如果(x,y)存在这个集合  那么  0<=x'<=x &a ...

  10. 洛谷 P1731 [NOI1999]生日蛋糕

    P1731 [NOI1999]生日蛋糕 题目背景 7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层 生日蛋糕,每层都是一个圆柱体. 设从下往上数第i(1<=i<=M ...