题目地址

Link

题解

虚点这种东西还是没有掌握好啊。

考虑建一个虚点,向已经学会的东西连一条边权为0的边,关系正常连边,单独学的从虚点连一条边过去。

然后做一遍最小生成树就得到答案了。

这题略卡常,上个快读稳一点。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <deque>
#include <ctime>
#include <map>
#include <set> #define ll long long
#define inf 0x3f3f3f3f
#define il inline namespace io { #define in(a) a = read()
#define out(a) write(a)
#define outn(a) out(a), putchar('\n') #define I_int ll
inline I_int read() {
I_int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
char F[200];
inline void write(I_int x) {
if (x == 0) return (void) (putchar('0'));
I_int tmp = x > 0 ? x : -x;
if (x < 0) putchar('-');
int cnt = 0;
while (tmp > 0) {
F[cnt++] = tmp % 10 + '0';
tmp /= 10;
}
while (cnt > 0) putchar(F[--cnt]);
}
#undef I_int }
using namespace io; using namespace std; #define N 8000010 int n, m, k, t, a[N], f[N];
struct edge {
int u, v, w;
}e[N]; bool operator < (edge a, edge b) {
return a.w < b.w;
} int find(int x) {
if(f[x] == x) return x;
return f[x] = find(f[x]);
} int main() {
in(n), in(m), in(k), in(t);
int cnt = 0;
for(int i = 1; i <= n; ++i) {
int x = read();
e[++cnt] = (edge) {i, n + 1, x};
}
++n;
for(int i = 1; i <= n; ++i) f[i] = i;
for(int i = 1; i <= k; ++i) {
int x = read();
e[++cnt] = (edge) {x, n, 0};
}
for(int i = 1; i <= m; ++i) {
int u = read(), v = read(), w = read();
e[++cnt] = (edge) {u, v, w};
}
sort(e+1,e+cnt+1);
ll ans = 0;
for(int i = 1; i <= cnt; ++i) {
int x = find(e[i].u), y = find(e[i].v);
if(x != y) {
f[y] = x;
ans += e[i].w;
}
}
if(ans > t) puts("No");
else puts("Yes");
// outn(ans);
}

牛客练习赛43C Tachibana Kanade Loves Review的更多相关文章

  1. 牛客练习赛43 Tachibana Kanade Loves Review C(最小生成树Kruskal)

    链接:https://ac.nowcoder.com/acm/contest/548/C来源:牛客网 题目描述 立华奏是一个刚刚开始学习 OI 的萌新. 最近,实力强大的 QingyuQingyu 当 ...

  2. 牛客练习赛43 Tachibana Kanade Loves Game (简单容斥)

    链接:https://ac.nowcoder.com/acm/contest/548/F来源:牛客网 题目描述 立华奏是一个天天打比赛的萌新. 省选将至,萌新立华奏深知自己没有希望进入省队,因此开始颓 ...

  3. 牛客练习赛43 Tachibana Kanade Loves Probability(快速幂)

    链接:https://ac.nowcoder.com/acm/contest/548/B来源:牛客网 题目描述 立华奏在学习初中数学的时候遇到了这样一道大水题: “设箱子内有 n 个球,其中给 m 个 ...

  4. 牛客练习赛43F Tachibana Kanade Loves Game

    题目地址 Link 题解 这题其实就是求1~n中有多少与2~20互质的数,然后其实只跟1~20里面的质数有关. 那么考虑容斥一下求出来一共有多少个不互质的,用n减一下就是互质的数的个数了.然后判一下a ...

  5. 牛客练习赛43D Tachibana Kanade Loves Sequence

    题目链接:https://ac.nowcoder.com/acm/contest/548/D 题目大意 略 分析 贪心,首先小于等于 1 的数肯定不会被选到,因为选择一个数的代价是 1,必须选择大于1 ...

  6. 牛客练习赛43B Tachibana Kanade Loves Probability

    题目链接:https://ac.nowcoder.com/acm/contest/548/C 题目大意 略 分析 利用快速幂先移到 k1 位,然后开始一个一个取余数. 代码如下 #include &l ...

  7. 牛客练习赛 43 B-Tachibana Kanade Loves Probability

    链接:https://ac.nowcoder.com/acm/contest/548/B 题目描述 立华奏在学习初中数学的时候遇到了这样一道大水题: “设箱子内有 n 个球,其中给 m 个球打上标记, ...

  8. 最小生成树--牛客练习赛43-C

    牛客练习赛43-C 链接: https://ac.nowcoder.com/acm/contest/548/C 来源:牛客网 题目描述 ​ 立华奏是一个刚刚开始学习 OI 的萌新. 最近,实力强大的 ...

  9. 牛客网 牛客练习赛43 C.Tachibana Kanade Loves Review-最小生成树(并查集+Kruskal)+建虚点+读入挂

    链接:https://ac.nowcoder.com/acm/contest/548/C来源:牛客网 Tachibana Kanade Loves Review 时间限制:C/C++ 2秒,其他语言4 ...

随机推荐

  1. 微信小程序本地的域名“不在以下request合法域名列表中”错误处理方法

  2. [本体论][UML][统一建模语言][软件建模][OWL]从本体论到UML到OWL

    以下内容,是关于软件建模的方法与思路. UML与OWL都是基于本体论的建模语言. 本体论(哲学) 本体论(信息科学) UML(统一建模语言) more info 参考:[设计语言][统一建模语言][软 ...

  3. Ubuntu系统启动后停在(initramfs)

    问题 今天我在启动虚拟机过程 遇到莫名其妙的问题,启动不了.如下图.提示某个文件系统错误了.例如我的就是 /dev/mapper/vagrant--vg-root . 上面问题 可把我急坏了,以为虚拟 ...

  4. LeetCode 206 Reverse Linked List 解题报告

    题目要求 Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5-> ...

  5. 【转载】word2vec原理推导与代码分析

    本文的理论部分大量参考<word2vec中的数学原理详解>,按照我这种初学者方便理解的顺序重新编排.重新叙述.题图来自siegfang的博客.我提出的Java方案基于kojisekig,我 ...

  6. webpack项目搭建

    1.新建一个文件目录,命令行进入当前目录,输入npm init 创建package.json文件 2.安装项目依赖webpack模块: npm install webpack --save-dev 3 ...

  7. OpenMVG学习笔记

    OpenMVG 是一个不错的SFM开源算法库,可以实现基于多视图像的稀疏重建. OpenMVG SfM pipelines run as a 4 step process:包含四个基本过程 1. Im ...

  8. 11.c#类的成员初始化顺序

    转自http://www.cnblogs.com/siceblue/archive/2009/01/15/1376430.html C#作为一种纯面向对象的话言,为它编写的整个代码里面到处都离不开对象 ...

  9. random函数的使用

    random作为随机函数用处很多,在Python里面也经常使用,特别是处理一些随机事件的时候,特别好用! 废话不多说,直接看下面的例子: random.randomrandom.random()   ...

  10. js对象添加动态属性

    在业务中,经常会遇到使用同个方法调用多个同类型接口,以下简单模拟两个API接口 // api-1 { code: 0, status: 200, title: 'web前端框架', list: [ { ...