Codevs4246 奶牛的身高
来源:互联网 发布:eduline修复完整源码 编辑:程序博客网 时间:2024/09/21 08:53
题目:http://codevs.cn/problem/4246/
分析:带权并查集,注意find中变量不能是全局。
代码:
#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int Tmax=30005;int n,m,fa[Tmax],height[Tmax];void init(){ memset(height,0,sizeof(height)); int i; for(i=1;i<=n;i++) fa[i]=i; return;}int find(int x){ int oldf,newf; if(fa[x]==x) return x; oldf=fa[x]; newf=find(fa[x]); height[x]+=height[oldf]; return fa[x]=newf;}int main(){ int T,i,u,v,w,fx,fy; bool ok; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); init();ok=false; for(i=1;i<=m;i++) { scanf("%d%d%d",&u,&v,&w); if(ok) continue; if(u==v&&w!=0){ printf("Bessie is blind.\n"); ok=true; continue; } fx=find(u); fy=find(v); if(fx==fy){ if(height[u]-height[v]!=w){ printf("Bessie is blind.\n"); ok=true; continue; }else continue; } else { fa[fx]=fy; height[fx]=w+height[v]-height[u];//height[fx]=w+height[v]; } } if(!ok) printf("Bessie's eyes are good\n"); } return 0;}
0 0
- Codevs4246 奶牛的身高
- 4246 奶牛的身高
- Codevs 4246 奶牛的身高
- [CODEVS P4246]奶牛的身高
- 奶牛身高
- codevs月赛 奶牛的身高
- 奶牛的身高(差分约束)
- 【codevs 4246】奶牛的身高 差分约束
- 有1000000头奶排着队,已知每只奶牛的身高,每只奶牛能看到自己前面比自己矮的奶牛,直到被一只比自己高的奶牛挡住。求出每只奶牛分别能看到几只前面的奶牛。
- BNU49098:神奇的身高
- 神奇的身高
- bnuoj49098 神奇的身高
- 身高
- xbox360 计算身高的办法
- BNUOJ49098 神奇的身高(LIS)
- BNUOJ-49098-神奇的身高
- BNU 49098 神奇的身高
- 输入一组身高在170到190之间(5个身高)比较身高差,选出身高差最小的两个身高,若身高差相同,选平均身高高的那两个身高,从小到达输出
- 利用karaf-maven-plugin制作kar部署包
- Java静态代码块,构造代码块,普通代码块
- Android自定义视图——onMeasur流程解析
- js生成环形进度条
- iOS开发技巧(系列十五:autolayout自动布局)
- Codevs4246 奶牛的身高
- AndroidManifest.xml文件解析
- PostgreSql 9.4.4 安装部署
- 上传本地文件到unix
- AE刷新的区别
- web工程中url地址的使用-----读书笔记
- 例10-1 uva11582(裴波那切数列)
- C++STL之组件
- 调用High-speed Charting Control图表VC6.0中该怎么设置