51nod 3 * problem
1640
题意:
一张无向图
在最小化最大边后求最大边权和
Slove:
sort
最小生成树
倒叙最大生成树
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string> using namespace std; #define LL long long #define gc getchar()
inline int read() {int x = , f = ; char c = gc;
while(c < '' || c > '') {if(c == '-') f = -; c = gc;}
while(c >= '' && c <= '') x = x * + c - '', c = gc; return x * f;}
inline LL read_LL() {LL x = ; char c = gc; while(c < '' || c > '') c = gc;
while(c >= '' && c <= '') x = x * + c - '', c = gc; return x;}
#undef gc const int N = 1e5 + ; int fa[N];
int A[N << ], U[N << ], V[N << ], W[N << ];
int n, m; bool Cmp(int a, int b) {return W[a] < W[b];} int Get(int x) {return fa[x] == x ? x : fa[x] = Get(fa[x]);} void Minst(int &R) {
for(int i = ; i <= n; i ++) fa[i] = i;
int js = ;
for(int i = ; i <= m; i ++) {
int fu = Get(U[A[i]]), fv = Get(V[A[i]]);
if(fu != fv) {
fa[fu] = fv;
js ++;
}
if(js == n - ) {
R = i;
while(W[A[R + ]] == W[A[i]]) R ++;
return ;
}
}
} inline long long Maxst(int R) {
for(int i = ; i <= n; i ++) fa[i] = i;
int js = ;
long long ret = ;
for(int i = R; i >= ; i --) {
int fu = Get(U[A[i]]), fv = Get(V[A[i]]);
if(fu != fv) {
fa[fu] = fv;
ret += W[A[i]];
js ++;
}
if(js == n - ) return ret;
}
} int main() {
n = read(), m = read();
for(int i = ; i <= m; i ++) A[i] = i, U[i] = read(), V[i] = read(), W[i] = read();
sort(A + , A + m + , Cmp);
int R;
Minst(R);
cout << Maxst(R);
return ;
}
1649
由于 1 - n 之间一定存在一种直接相连的道路
判断哪种直接相连
跑另外一种的最短路
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string> using namespace std; #define LL long long #define gc getchar()
inline int read() {int x = ; char c = gc; while(c < '' || c > '') c = gc;
while(c >= '' && c <= '') x = x * + c - '', c = gc; return x;}
inline LL read_LL() {LL x = ; char c = gc; while(c < '' || c > '') c = gc;
while(c >= '' && c <= '') x = x * + c - '', c = gc; return x;}
#undef gc const int N = , oo = ; int Map[N][N], Bmap[N][N];
int n, m; int main() {
n = read(), m = read();
for(int i = ; i <= n; i ++) for(int j = ; j <= n; j ++) Map[i][j] = oo;
for(int i = ; i <= n; i ++) Map[i][i] = ;
for(int i = ; i <= n; i ++) for(int j = ; j <= n; j ++) Bmap[i][j] = oo;
for(int i = ; i <= n; i ++) Bmap[i][i] = ;
for(int i = ; i <= m; i ++) {
int u = read(), v = read();
Map[u][v] = Map[v][u] = ;
}
if(Map[][n] == ) {
for(int i = ; i <= n; i ++)
for(int j = ; j <= n; j ++) {
if(i == j) continue;
if(Map[i][j] == oo) Bmap[i][j] = ;
}
for(int k = ; k <= n; k ++)
for(int i = ; i <= n; i ++)
for(int j = ; j <= n; j ++)
Bmap[i][j] = min(Bmap[i][j], Bmap[i][k] + Bmap[k][j]);
if(Bmap[][n] == oo) cout << -;
else cout << Bmap[][n];
} else {
for(int k = ; k <= n; k ++)
for(int i = ; i <= n; i ++)
for(int j = ; j <= n; j ++)
Map[i][j] = min(Map[i][j], Map[i][k] + Map[k][j]);
if(Map[][n] == oo) cout << -;
else cout << Map[][n];
}
return ;
}
1535
图是树的充要条件
$m = n - 1$ && 图联通
由于题目无自环
所以不存在二元环
并且若 $m >= n - 1$
则图联通
此时若 $m = n$
那么就会存在且只存在一个三元环(或更大)
因此只需判断 $n = m$ 即可
if(n == m) cout << "FHTAGN!";
else cout << "NO";
51nod 3 * problem的更多相关文章
- 51nod 算法马拉松 34 Problem D 区间求和2 (FFT加速卷积)
题目链接 51nod 算法马拉松 34 Problem D 在这个题中$2$这个质数比较特殊,所以我们先特判$2$的情况,然后仅考虑大于等于$3$的奇数即可. 首先考虑任意一个点对$(i, j)$ ...
- 51nod 1622 集合对[算法马拉松19 C]
题目链接:https://www.51nod.com/contest/problem.html#!problemId=1622 第一次参加算法马拉松,我就是去看大神们疯狂秒题,然后感受绝望的orz.. ...
- 51nod算法马拉松 contest7
A题 链接:http://www.51nod.com/contest/problem.html#!problemId=1417 推荐链接:http://blog.csdn.net/a837199685 ...
- pku 1401 Factorial 算数基本定理 && 51nod 1003 阶乘后面0的数量
链接:http://poj.org/problem?id=1401 题意:计算N!的末尾0的个数 思路:算数基本定理 有0,分解为2*5,寻找2*5的对数,2的因子个数大于5,转化为寻找因子5的个数. ...
- 51nod 1103 N的倍数(抽屉原理)
1103 N的倍数 题目来源: Ural 1302 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 一个长度为N的数组A,从A中选出若干个数,使得这些数的和是N的倍 ...
- 51nod 1486 大大走格子(容斥原理)
1486 大大走格子 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 160 难度:6级算法题 有一个h行w列的棋盘,里面有一些格子是不能走的,现在要 ...
- 51nod 1204 Parity(并查集应用)
1204 Parity 题目来源: Ural 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 你的朋友写下一串包含1和0的串让你猜,你可以从中选择一个连续的子串 ...
- 51nod 1364 最大字典序排列(线段树)
1364 最大字典序排列基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 给出一个1至N的排列,允许你做不超过K次操作,每次操作可以将相邻的两个数交换,问能够得到的字 ...
- 51nod 1682 中位数计数
1682 中位数计数基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 中位数定义为所有值从小到大排序后排在正中间的那个数,如果值有偶数个,通常取最中间的两个数值的平均 ...
随机推荐
- Linux中光标消失解决办法
假如Linux下光标消失,不要急: echo -e "\033[?25l" 隐藏光标 echo -e "\033[?25h" 显示光标 (转载自:https: ...
- PB之取下来列修改后的值(AcceptText)
AcceptText()功能 将“漂浮”在数据窗口控件上编辑框的内容放入到数据窗口控件的当前项中(主缓区中).在将数据放入到当前项之前,编辑框中的数据必须通过有效性规则检查语法 dwcontrol. ...
- DNS 解析
DNS即为Domain Name System的缩写形式,就是所谓的域名系统,它是互联网的一项服务.它作为将域名和IP地址相互映射的一个分布式数据库,能够使人更方便地访问互联网. 如果想访问某个网站( ...
- An unavoidable detour for home CodeForces - 814E (dp)
大意: 给定一棵树每个点的度数, 求所有满足条件的树的个数 每个点到$1$的最短路唯一 假设$l_i$为点$i$到$1$的最短距离, 那么$l_i\ge l_{i-1}$ 每个点度数范围$2\le d ...
- sqlserver exists 与 in 的区别
使用 EXISTS 方式 select * from A a where EXISTS(select b.mainInfoId from B b where b.mainInfoId=a.main ...
- ReLU函数的缺陷
ReLU激活功能并不完美. 它有一个被称为 “ReLU 死区” 的问题:在训练过程中,一些神经元会“死亡”,即它们停止输出 0 以外的任何东西.在某些情况下,你可能会发现你网络的一半神经元已经死亡,特 ...
- centos+docker+jenkins
1.直接运行jenkins镜像,无该镜像会直接下载 docker run -p 8080:8080 -p 50000:50000 -d -v /home/jenkins-home-docker:/va ...
- php的文件上传及下载,附带显示文件及目录
主页面wenjianceshi.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ...
- Fortify漏洞之Path Manipulation(路径篡改)
继续对Fortify的漏洞进行总结,本篇主要针对 Path Manipulation(路径篡改)的漏洞进行总结,如下: 1.Path Manipulation(路径篡改) 1.1.产生原因: 当满足以 ...
- Fortify漏洞之Cross-Site Scripting(XSS 跨站脚本攻击)
书接上文,继续对Fortify漏洞进行总结,本篇主要针对XSS跨站脚步攻击漏洞进行总结,如下: 1.Cross-Site Scripting(XSS 跨站脚本攻击) 1.1.产生原因: 1. 数据通过 ...