首先计算图的联通情况,如果图本身不联通一定不会出现生成树,输出"NO",之后清空,加白边,看最多能加多少条,清空,加黑边,看能加多少条,即可得白边的最大值与最小值,之后判断Fibonacci数是否在这两个之间,如果是输出yes,否则no。

然而,,然而,,我看的题解有问题!!!!!调了俩小时愣是没找出错误来,,然后把题解交了发现过不了,,,,真是够了。,。,。,

第二天上午终于A了,,满分程序:

 #include <cstdio>
#include <cstring>
#include <algorithm> struct data {
int x1;
int y1;
int z1;
};
const int maxn = + ;
int father[maxn];
int f[maxn];
data p[maxn];
int T;
int n, m; bool cmp(data aa, data bb) {
return (aa.z1 < bb.z1);
} int getfather(int x) {
if (father[x] == x) return x;
return (father[x] = getfather(father[x]));
} bool solve (void) {
int cur = n;
for (int i = ; i <= m; i++) {
int tx = getfather(p[i].x1);
int ty = getfather(p[i].y1);
if (tx != ty) {
father[tx] = ty;
cur--;
}
}
if (cur > ) return ;
return ;
} int main () {
f[] = ;
f[] = ;
for (int i = ; i <= ; i++) {
f[i] = f[i-] + f[i-];
}
scanf("%d", &T);
for (int kase = ; kase <= T; kase++) {
printf("Case #%d: ", kase);
scanf("%d %d", &n, &m);
for (int i = ; i <= n; i++) father[i] = i;
for (int i = ; i <= m; i++) scanf("%d %d %d", &p[i].x1, &p[i].y1, &p[i].z1);
std :: sort(p + , p + m + , cmp);
if (solve()) printf("No\n");
else {
for (int i = ; i <= n; i++) father[i] = i;
int smin = ;
for (int i = ; i <= m; i++) {
int tx = getfather(p[i].x1);
int ty = getfather(p[i].y1);
if (tx != ty) {
father[tx] = ty;
if (p[i].z1 == ) smin++;
}
}
int smax = ;
for (int i = ; i <= n; i++) father[i] = i;
for (int i = m; i >= ; i--) {
int tx = getfather(p[i].x1);
int ty = getfather(p[i].y1);
if (tx != ty) {
father[tx] = ty;
if (p[i].z1 == ) smax++;
}
}
bool flag = ;
for (int i = ; i <= ; i++)
if (smin <= f[i] && smax >= f[i]) {
flag = ;
break;
}
if (flag) printf("Yes\n");
else printf("No\n");
}
}
return ;
}

hdu 4786 Fibonacci Tree 乱搞 智商题目 最小生成树的更多相关文章

  1. HDU 4786 Fibonacci Tree(生成树,YY乱搞)

    http://acm.hdu.edu.cn/showproblem.php? pid=4786 Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others ...

  2. hdu 4786 Fibonacci Tree (2013ACMICPC 成都站 F)

    http://acm.hdu.edu.cn/showproblem.php?pid=4786 Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others) ...

  3. HDU 4786 Fibonacci Tree 最小生成树

    Fibonacci Tree 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4786 Description Coach Pang is intere ...

  4. HDU 4786 Fibonacci Tree

    Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) P ...

  5. HDU 4786 Fibonacci Tree (2013成都1006题)

    Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  6. hdu 4786 Fibonacci Tree(最小生成树)

    Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  7. hdoj 4786 Fibonacci Tree【并查集+最小生成树(kruskal算法)】

    Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  8. 【HDU 4786 Fibonacci Tree】最小生成树

    一个由n个顶点m条边(可能有重边)构成的无向图(可能不连通),每条边的权值不是0就是1. 给出n.m和每条边的权值,问是否存在生成树,其边权值和为fibonacci数集合{1,2,3,5,8...}中 ...

  9. HDU 5167 Fibonacci 筛法+乱搞

    题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5167 题意: 给你一个x,判断x能不能由斐波那契数列中的数相乘得到(一个数可以重复使用) ...

随机推荐

  1. 论文阅读《End-to-End Learning of Geometry and Context for Deep Stereo Regression》

    端到端学习几何和背景的深度立体回归 摘要     本文提出一种新型的深度学习网络,用于从一对矫正过的立体图像回归得到其对应的视差图.我们利用问题(对象)的几何知识,形成一个使用深度特征表示的代价量(c ...

  2. Python数学实现二元一次方程

    import cmath import math import sys def get_float(msg,allow_zero): x = None while x is None: try: x ...

  3. 【Python 学习】continue ,break 的使用

    # continue 跳出本轮循环并进入下一次循环# break 终止当前循环,跳出循环体 1. continue 使用案例 : for i in range(5): if i < 3: pri ...

  4. ES6特性:(阮一峰老师)学习总结

    ES6(阮一峰)学习总结   1.块级作用域的引入 在ES6之前,js只有全局作用域和函数作用域,ES6中let关键字为其引入了块级作用域. { var a = 5; let b = 6; } con ...

  5. Vue经典开源项目

    Vue常用的开源项目和插件库 UI组件 element ★34,784 - 饿了么出品的基于Vue2的web UI工具套件storybook ★33,503 - 响应式UI 开发及测试环境Vux ★1 ...

  6. Windows里正确安装Zookeeper以服务运行

    不多说,直接上干货! 为什么要在Win下来安装Zookeeper呢? 其实玩过大数据的人很清楚,在Linux下我更不说了.在win下,如Disconf .Dubbo等应用. 所以,它的应用是非常广的. ...

  7. Methods and systems for sharing common job information

    Apparatus and methods are provided for utilizing a plurality of processing units. A method comprises ...

  8. (转)彻底学会使用epoll(一)——ET模式实现分析

    注:之前写过两篇关于epoll实现的文章,但是感觉懂得了实现原理并不一定会使用,所以又决定写这一系列文章,希望能够对epoll有比较清楚的认识.是请大家转载务必注明出处,算是对我劳动成果的一点点尊重吧 ...

  9. Android application framework 分析[in process]

    application activity application service application UI system application sdk tool JVM 1 activity t ...

  10. ZOJ Problem Set - 3820 Building Fire Stations 【树的直径 + 操作 】

    题目:problemId=5374" target="_blank">ZOJ Problem Set - 3820 Building Fire Stations 题 ...