UVA1160 X-Plosives
思路
每个元素设为点,化合物设为边
不能出现k条边k个点的环
直接并查集检查即可
代码
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int fa[100100],ans=0,a,b;
void init(void){
ans=0;
for(int i=1;i<=100010;i++)
fa[i]=i;
}
int find(int x){
return (fa[x]==x)?x:fa[x]=find(fa[x]);
}
void merge(int x,int y){
if(find(x)==find(y))
ans++;
else
fa[find(x)]=find(y);
}
int main(){
freopen("test.in","r",stdin);
freopen("test.out","w",stdout);
while(scanf("%d",&a)==1){
init();
while(a!=-1){
scanf("%d",&b);
merge(a,b);
scanf("%d",&a);
}
printf("%d\n",ans);
}
return 0;
}
UVA1160 X-Plosives的更多相关文章
- uva1160 易爆物
#include<iostream>#include<cstdio>#include<algorithm>#include<cstdlib>using ...
随机推荐
- linux 的基本操作(linux系统的日常管理)
系统的日常管理 笔者在前面介绍的内容都为linux系统基础类的,如果你现在把前面的内容全部很好的掌握了,那最好了.不过笔者要说的是,即使你完全掌握了,你现在还是不能作为一名合格的linux系统管理员的 ...
- StreamSocket
转载自:http://blog.csdn.net/yuanguozhengjust/article/details/19175085 StreamSocket的基本流程和一般的Socket通信操作类似 ...
- Java 读取某文件下的所有文件的大小 并将所有文件的文件名,以及对应大小输出在xls表格里
import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.In ...
- python全栈开发 * 线程锁 Thread 模块 其他 * 180730
一,线程Thread模块1.效率更高(相对于进程) import time from multiprocessing import Process from threading import Thre ...
- partial_sum
版本1: template < class InputIterator, class OutputIterator > OutputIterator partial_sum(InputIt ...
- vue的属性样式绑定,
<template> <div id="app"> <div v-html="H"></div> //绑定ht ...
- 我了解到的新知识之—Apple Captive Portal 网页认证登陆公共Wifi
因为今天一个用户遇到选择公司WiFi后,无法弹出网页认证登陆界面的问题,随即上网搜索相关信息,因为公司内没有VPN,无法FQ,只能用bing来搜索一下相关信息了. Captive Portal听起来好 ...
- Gym 101981K - Kangaroo Puzzle - [玄学][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem K]
题目链接:http://codeforces.com/gym/101981/problem/K Your friend has made a computer video game called “K ...
- Hadoop开发环境配置1-maven安装配置
1.下载maven安装包:apache-maven-3.3.9-bin.zip 下载地址: http://archive.apache.org/dist/maven/maven-3/3.3.9/bin ...
- odoo配置文件详解
addons模块的查找路径 addons_path = D:\odoo\Odoo 10.0\server\odoo\addons 超级管理员(用于创建,还原和备份数据库的操作) admin_passw ...