POJ 1988
来源:互联网 发布:unity3d 关闭垂直同步 编辑:程序博客网 时间:2024/04/25 03:20
【题目分析】
并查集。
【代码】
#include <cstdio>#include <cmath>#include <cstring>#include <iostream>#include <algorithm>using namespace std;int f[50001],w[50001],s[50001];char ss[11];inline int gf(int k){ if (f[k]==k) return k; int t=f[k]; f[k]=gf(f[k]); w[k]+=w[t]; return f[k];}inline void un(int x,int y){ x=gf(x);y=gf(y); f[x]=y; w[x]+=s[y]; s[y]+=s[x]; s[x]=0;}int main(){ int n; scanf("%d",&n); for (int i=1;i<=30000;++i) f[i]=i,w[i]=0,s[i]=1; while (scanf("%s",ss)!=EOF) {// printf("%s\n",s); if (ss[0]=='M'){ int x,y; scanf("%d%d",&x,&y); un(x,y); } else{ int x; scanf("%d",&x); gf(x); printf("%d\n",w[x]); } }}
0 0
- poj 1988 &&poj 2524
- poj 1988
- POJ 1988
- poj 1988
- poj-1988
- POJ 1988
- POJ 1988
- 小比赛(POJ 2992,UVALive 4108,POJ 2263,POJ 3617,HDU 5305,POJ 1988,POJ 1679,POJ 3481)
- poj 1988 Cube Stacking
- poj 1988 Cube Stacking
- poj 1988 Cube Stacking
- POJ-1988 Cube Stacking
- POJ 1988 Cube Stacking
- POJ 1988 Cube Stacking
- POJ 1988 Cube Stacking
- poj 1988 Cube Stacking
- POJ 1988 Cube Stacking
- POJ 1988 Cube Stacking
- 一路走来,从自学到工作这一年我学到了什么?
- Java内存泄漏
- Android四大组件之Activity
- leetcode 上的一道dfs问题和baidu online test的一道题(待总结)
- 最小费用最大流问题----poj 2135
- POJ 1988
- HONOR-MILTER 反垃圾邮件网关
- cf 155A Boredom dp
- 单例模式
- Hello Visitors!
- v2.7.3版本去版权完全版
- 这些日子的总结
- Mac OS X安装gnu-sed等命令行工具
- lightoj-1122-Digit Count【DP】