UVALive - 3644 X-Plosives
来源:互联网 发布:淘宝钱货一方 编辑:程序博客网 时间:2024/06/06 17:10
题意:每个化合物都是有两种元素组成的,如果车上存在k个简单化合物时,如果它和已装车的化合物形成易燃物的话,你就应该拒绝装车,否则装车,输出没有装车的个数
思路:简单的并查集应用
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 100005;int f[MAXN];int find(int x){ if (x != f[x]) f[x] = find(f[x]); return f[x];}int main(){ int x,y; while (scanf("%d",&x) != EOF){ for (int i = 0; i < MAXN; i++) f[i] = i; int ans = 0; while (x != -1){ scanf("%d",&y); int fx = find(x),fy = find(y); if (fx == fy) ans++; else f[fx] = fy; scanf("%d",&x); } printf("%d\n",ans); } return 0;}
0 0
- UVALive 3644 X-Plosives
- UVALive 3644 X-Plosives
- UVALive 3644 X-Plosives
- UVALive - 3644 X-Plosives
- UVALive 3644 X-Plosives
- UVALive - 3644 X-Plosives
- uvalive 3644 X-Plosives
- UVALive 3644 X-Plosives 并查集
- UVALive - 3644 X-Plosives 并查集
- UVALive - 3644 X-Plosives 并查集
- 【暑假】[实用数据结构]UVAlive 3644 X-Plosives
- UVALive - 3644X-Plosives(并查集)
- UVALive - 3644 - X-Plosives (并查集!!)
- UVALive(LA) 3644 X-Plosives (并查集)
- uvalive 3644 X-Plosives(并查集)
- UVALive 3644 X-Plosives(简单并查集)
- UVALive 3644 X-Plosives (并查集)
- X-Plosives +uvalive+并查集+水题
- JSON解析
- openCV中测试算法时间复杂度
- 应用层的AIDL用法
- wordpress通过文章的附加字段查询文章(query_posts)
- window(win7)+linux(ubuntu)双系统的安装以及windows重装后的引导修复问题
- UVALive - 3644 X-Plosives
- 学习TQ2440之裸奔第一章-电子相框
- 雨,一首美丽的歌
- 无向图最小费用最大流+uva10594
- 一段小小的插曲
- python 内建属性 与 获取当前运行的类名函数名
- JAVA APNS苹果推送
- Framework中的AIDL
- 如何远程debug tomcat