Codeforces 875F Royal Questions (看题解)
我还以为是什么板子题呢。。。
我们把儿子当做点, 公主当做边, 然后就是求边权值最大基环树森林。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long
using namespace std; const int N = 2e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-; int n, m, ans, a[N], b[N], w[N], fa[N], id[N];
bool vis[N]; int getRoot(int x) {
return fa[x] == x ? x : fa[x] = getRoot(fa[x]);
} bool cmp(const int&a, const int& b) {
return w[a] > w[b];
} int main(){
scanf("%d%d", &n, &m);
for(int i = ; i <= m; i++)
scanf("%d%d%d", &a[i], &b[i], &w[i]);
for(int i = ; i <= m; i++) id[i] = i;
for(int i = ; i <= n; i++) fa[i] = i;
sort(id + , id + + m, cmp);
for(int i = ; i <= m; i++) {
int p = id[i];
int x = getRoot(a[p]);
int y = getRoot(b[p]);
if(x != y && (!vis[x] || !vis[y])) {
ans += w[p];
if(!vis[x]) fa[x] = y;
else fa[y] = x;
} else if(!vis[x]){
ans += w[p];
vis[x] = true;
}
}
printf("%d\n", ans);
return ;
}
/*
*/
Codeforces 875F Royal Questions (看题解)的更多相关文章
- Codeforces 269C Flawed Flow (看题解)
我好菜啊啊啊.. 循环以下操作 1.从队列中取出一个顶点, 把哪些没有用过的边全部用当前方向. 2.看有没有点的入度和 == 出度和, 如果有将当前的点加入队列. 现在有一个问题就是, 有没有可能队列 ...
- Codeforces 436E Cardboard Box (看题解)
Cardboard Box 贪了个半天贪不对, 我发现我根本就不会贪心. 我们先按b排序, 然后枚举选两颗心的b的最大值, 在这个之前的肯定都要选一个, 因为前面的要是一个都没选的话, 你可以把当前选 ...
- Codeforces 1045C Hyperspace Highways (看题解) 圆方树
学了一下圆方树, 好神奇的东西呀. #include<bits/stdc++.h> #define LL long long #define fi first #define se sec ...
- Codeforces 1137D Cooperative Game (看题解)
Cooperative Game 智商题, 感觉不太能推出来, 虽然看看证明过程是对的. #include<bits/stdc++.h> #define LL long long #def ...
- Codeforces 983C Elevator dp (看题解)
Elevator 怎么今天写啥题都不会写啊, 我是傻了吗.. 把电梯里面四个人的目标点当作状态, 然后暴力转移. #include<bits/stdc++.h> #define LL lo ...
- Codeforces 924D Contact ATC (看题解)
Contact ATC 我跑去列方程, 然后就gg了... 我们计每个飞机最早到达时间为L[ i ], 最晚到达时间为R[ i ], 对于面对面飞行的一对飞机, 只要他们的时间有交集则必定满足条件. ...
- Codeforces 830C Bamboo Partition (看题解)
Bamboo Partition 列公式, 整除分块, 想不到, 好菜啊. #include<bits/stdc++.h> #define LL long long #define fi ...
- Codeforces 750E New Year and Old Subsequence 线段树 + dp (看题解)
New Year and Old Subsequence 第一感觉是离线之后分治求dp, 但是感觉如果要把左边的dp值和右边的dp值合起来, 感觉很麻烦而且时间复杂度不怎么对.. 然后就gun取看题解 ...
- Codeforces 1017F The Neutral Zone (看题解)
这题一看就筛质数就好啦, 可是这怎么筛啊, 一看题解, 怎么会有这么骚的操作. #include<bits/stdc++.h> #define LL long long #define f ...
随机推荐
- zabbix3.0.4利用iostat工具监控centos主机磁盘IO
该监控基于iostat,然后iostat 命令用来监视系统输入/输出设备负载 1.安装IOSTAT工具 # yum install sysstat -y 测试iostat 查看所有硬盘io # ios ...
- Linux root密码忘记了怎么办?
一.找回root密码: 1. 开机出现 Booting Red Hat Enterprise Linux Client (…) in 3 seconds … 按任意键进入menu菜单: 2. 选择当前 ...
- LabVIEW---vi图标和符号的制作
前言: 使用图形化设计语言进行开发时候,为VI添加说明的一个重要的方法是为其建立一个形象的图标,每个VI都在前面板后程序框图的右上角有一个图标,它是VI的图形化表示.如果VI当作子VI调用,该图标就会 ...
- Python-Django-Ajax进阶
ajax上传文件: <h2>基于ajax上传文件</h2><p>名字 <input type="text" id="filena ...
- python之hashlib
简介: 用于加密相关的操作,代替了md5模块和sha模块,主要提供SHA1,SHA224,SHA256,SHA384,SHA512,MD5算法.在python3中已经废弃了md5和sha模块,简单说明 ...
- jmeter测试mysql遇到的问题
1. 1.防火墙未关 错误: Communications link failure The last packet sent successfully to the server was 0 mil ...
- Confluence 6 创建-使用-删除快捷链接
创建快捷链接 如何创建一个快捷键链接: 在屏幕的右上角单击 控制台按钮 ,然后选择 General Configuration 链接. 在左侧面板中选择 快捷链接(Shortcut Links). 为 ...
- 高性能JavaScript读后感
这本书让lz对js性能优化有了更深刻的理解,现在因为我们通常用第三方构建工具webpack.gulp等诸如此类,之前总是听说什么dom操作影响性能呢,对这个概念总是有点模糊,但看完这本书之后后,相对而 ...
- jquery 的鼠标事件/淡入淡出/绑定
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- 基于BootStrap的Collapse折叠(包含回显展开折叠的对应状态)
情况描述:为了改善页面上的input框太多,采用∧∨折叠展开,这个小东西来控制,第一次做,记录一下ヾ(◍°∇°◍)ノ゙下边是Code 代码: //html代码 <div id="col ...