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 = 0, f = 1; char c = gc;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = gc;}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = gc; return x * f;}
inline LL read_LL() {LL x = 0; char c = gc; while(c < '0' || c > '9') c = gc;
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = gc; return x;}
#undef gcconst int N = 1e5 + 10;int fa[N];
int A[N << 1], U[N << 1], V[N << 1], W[N << 1];
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 = 1; i <= n; i ++) fa[i] = i;int js = 0;for(int i = 1; i <= m; i ++) {int fu = Get(U[A[i]]), fv = Get(V[A[i]]);if(fu != fv) {fa[fu] = fv;js ++;}if(js == n - 1) {R = i;while(W[A[R + 1]] == W[A[i]]) R ++;return ;}}
}inline long long Maxst(int R) {for(int i = 1; i <= n; i ++) fa[i] = i;int js = 0;long long ret = 0;for(int i = R; i >= 1; 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 - 1) return ret;}
}int main() {n = read(), m = read();for(int i = 1; i <= m; i ++) A[i] = i, U[i] = read(), V[i] = read(), W[i] = read();sort(A + 1, A + m + 1, Cmp);int R;Minst(R);cout << Maxst(R);return 0;
}

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 = 0; char c = gc; while(c < '0' || c > '9') c = gc;
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = gc; return x;}
inline LL read_LL() {LL x = 0; char c = gc; while(c < '0' || c > '9') c = gc;
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = gc; return x;}
#undef gcconst int N = 410, oo = 999999999;int Map[N][N], Bmap[N][N];
int n, m;int main() {n = read(), m = read();for(int i = 1; i <= n; i ++) for(int j = 1; j <= n; j ++) Map[i][j] = oo;for(int i = 1; i <= n; i ++) Map[i][i] = 0;for(int i = 1; i <= n; i ++) for(int j = 1; j <= n; j ++) Bmap[i][j] = oo;for(int i = 1; i <= n; i ++) Bmap[i][i] = 0;for(int i = 1; i <= m; i ++) {int u = read(), v = read();Map[u][v] = Map[v][u] = 1;}if(Map[1][n] == 1) {for(int i = 1; i <= n; i ++) for(int j = 1; j <= n; j ++) {if(i == j) continue;if(Map[i][j] == oo) Bmap[i][j] = 1;}for(int k = 1; k <= n; k ++)for(int i = 1; i <= n; i ++)for(int j = 1; j <= n; j ++)Bmap[i][j] = min(Bmap[i][j], Bmap[i][k] + Bmap[k][j]);if(Bmap[1][n] == oo) cout << -1;else cout << Bmap[1][n];} else {for(int k = 1; k <= n; k ++)for(int i = 1; i <= n; i ++)for(int j = 1; j <= n; j ++)Map[i][j] = min(Map[i][j], Map[i][k] + Map[k][j]);if(Map[1][n] == oo) cout << -1;else cout << Map[1][n];}return 0;
}

1535
图是树的充要条件
$m = n - 1$ && 图联通
由于题目无自环
所以不存在二元环
并且若 $m >= n - 1$
则图联通
此时若 $m = n$
那么就会存在且只存在一个三元环(或更大)
因此只需判断 $n = m$ 即可

if(n == m) cout << "FHTAGN!";
else cout << "NO";

转载于:https://www.cnblogs.com/shandongs1/p/9591918.html

51nod 3 * problem相关推荐

  1. 0 和 5 ( 51Nod - 1433 )

    0 和 5 来源: 51Nod - 1433 Problem Description 小K手中有n张牌,每张牌上有一个一位数的数,这个字数不是0就是5.小K从这些牌在抽出任意张(不能抽0张),排成一行 ...

  2. 写过的比较难受的题目

    难受的 100. 增减序列 - AcWing题库 1460. 我在哪? - AcWing题库 Problem - 3410 (hdu.edu.cn) 题目-最长公共子序列Lcs (51nod.com) ...

  3. 51nod 1270 数组的最大代价

    1270 数组的最大代价 题目来源: HackerRank 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 数组A包含N个元素A1, A2......AN.数组B包 ...

  4. Problem 2238 Daxia Wzc's problem 1627 瞬间移动

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1627 http://acm.fzu.edu.cn/problem.php ...

  5. 计蒜客/51Nod题目

    题目 换位置(1) 链接https://nanti.jisuanke.com/t/T1971 思路:两两交换次序使得数组逆序,第一个到最后位置需要n-1步,第二个到倒数第二个需要n-2步,第三个到倒数 ...

  6. 51Nod幼儿园霸王

    问题 1957 幼儿园霸王 链接https://www.51nod.com/Challenge/Problem.html#problemId=1957 1.0 秒 131,072.0 KB 5 分 初 ...

  7. ACM学习历程—51NOD 1685 第K大区间2(二分 树状数组 中位数)

    http://www.51nod.com/contest/problem.html#!problemId=1685 这是这次BSG白山极客挑战赛的E题. 这题可以二分答案t. 关键在于,对于一个t,如 ...

  8. 51Nod 1494 选举拉票(权值线段树)

    http://www.51nod.com/Challenge/Problem.html#!#problemId=1494 题解 一开始有start个人投自己,num表示当前已经收买了多少人,从大到小枚 ...

  9. 51nod 省选联测 R2

    51nod 省选联测 R2 上场的题我到现在一道都没A,等哪天改完了再写题解吧,现在直接写第二场的. 第二场比第一场简单很多(然而这并不妨碍我不会做). A.抽卡大赛:http://www.51nod ...

最新文章

  1. ES6笔记(4)-- Symbol类型
  2. 达夫设备(Duff‘s Device)
  3. 控制反转(Ioc)和依赖注入(DI)
  4. ftp服务器不显示缩略图,ftp服务器不显示缩略图
  5. python 对excel文件进行分词并进行词频统计_python 词频分析
  6. CorrTracker解读
  7. Uboot初次编译、烧写、启动(启动界面log简析)
  8. java poi 导入日期为空
  9. tomcat中间件的默认端口号_Tomcat下载安装及配置
  10. 取消回车表单自动提交
  11. Java简易小说阅读器
  12. 动软代码生成器生成批量代码相关步骤
  13. c盘满了怎么办?如何快速清理内存(6个方法)
  14. linux清理磁盘空间的脚本,使用 shell 自动释放磁盘空间
  15. Javascript中new关键字和this指向
  16. matlab subs命令,Matlab中subs函数
  17. 朽木第一至三季/全集Deadwood迅雷下载
  18. python模拟手机app签到_python +adb控制手机自动化签到
  19. win7装xp双系统_UEFI新PC装Win7 32位系统:巧用”硬盘保护卡“解决
  20. 旅游地图制作_手把手教你用旅游神器App:谷歌地图

热门文章

  1. 开机报警disk boot sector is to be modified
  2. Android Stdio换源以及配置项目
  3. 计算机硬件人员专业知识技能,2017年江苏省职业学校技能大赛(计算机硬件)竞赛实施方案...
  4. python调用nacos账号密码,Python脚本,使用私钥(如果可用)或用户名密码
  5. 解决incorrect 'only available in ES6' warning (W119) with options `moz: true, esversion: 6` 报错问题...
  6. linux centos6.5 网络配置
  7. python【接上篇】
  8. 两种高效的事件处理模式
  9. ScriptManager调用 无参数WebService
  10. 实现人脸识别“干货”