Codeforces Round #541--1131F. Asya And Kittens(基础并查集)
https://codeforces.com/contest/1131/problem/F
#include<bits/stdc++.h>
using namespace std;
int n;
vector<vector<int> > v;
vector<int> par;
int find(int d){
if(d==par[d])
return d;
else
return par[d]=find(par[d]);
}
void unite(int x,int y){
x=find(x);
y=find(y);
if(v[x].size()<v[y].size())
swap(x,y);
for(int i=;i<v[y].size();i++)
v[x].push_back(v[y][i]);
par[y]=x;
}
int main(){
int n;
cin>>n;
v.resize(n+);
par.resize(n+);
for(int i=;i<=n;i++){
par[i]=i;
v[i].push_back(i);
}
for(int i=;i<n-;i++){
int a,b;
cin>>a>>b;
unite(a,b);
}
for(int x:v[find()])cout<<x<<' ';
cout<<endl;
return ;
}
Codeforces Round #541--1131F. Asya And Kittens(基础并查集)的更多相关文章
- Codeforces Round #541 F. Asya And Kittens
题面: 传送门 题目描述: Asya把N只(从1-N编号)放到笼子里面,笼子是由一行N个隔间组成.两个相邻的隔间有一个隔板. Asya每天观察到有一对想一起玩,然后就会把相邻的隔间中的隔板取出来,使两 ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces Educational Codeforces Round 5 C. The Labyrinth 带权并查集
C. The Labyrinth 题目连接: http://www.codeforces.com/contest/616/problem/C Description You are given a r ...
- Educational Codeforces Round 14 D. Swaps in Permutation(并查集)
题目链接:http://codeforces.com/contest/691/problem/D 题意: 题目给出一段序列,和m条关系,你可以无限次互相交换这m条关系 ,问这条序列字典序最大可以为多少 ...
- Codeforces Round #245 (Div. 2) B. Balls Game 并查集
B. Balls Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/430/problem ...
- Codeforces Round #345 (Div. 1) E. Clockwork Bomb 并查集
E. Clockwork Bomb 题目连接: http://www.codeforces.com/contest/650/problem/E Description My name is James ...
- Codeforces Round #345 (Div. 2) E. Table Compression 并查集
E. Table Compression 题目连接: http://www.codeforces.com/contest/651/problem/E Description Little Petya ...
- Codeforces Round #603 (Div. 2) D. Secret Passwords 并查集
D. Secret Passwords One unknown hacker wants to get the admin's password of AtForces testing system, ...
- Educational Codeforces Round 64 (Rated for Div. 2)D(并查集,图)
#include<bits/stdc++.h>using namespace std;int f[2][200007],s[2][200007];//并查集,相邻点int find_(in ...
随机推荐
- 性能测试Jmeter扩展学习-添加自定义函数
我们在使用jmeter的时候有时候会碰到jmeter现有插件或功能也无法支持的场景,比如前端加密,此时我们就需要自己手动编写函数并导入了,下面就是手动修改并导入的过程. 首先我们需要下载jmeter源 ...
- Tomcat、TongWeb5.0、TongWeb6.0部署solr
将solr,solr-4.7.2复制到某一路径下,比如F盘根目录. 1.tomcat中进行配置,配置如下: <Context docBase="F:/solr" reload ...
- python-反射案例讲解
login.py#!/usr/bin/dev python# coding:utf-8 def index(): print u'欢迎访问xx网站首页' def login(): print u'登录 ...
- ElasicSearch(3) 安装elasticsearch-head
https://github.com/mobz/elasticsearch-head 1.git install git 2.git clone git://github.com/mobz/elast ...
- charles 注册码
感谢@那时纯真 提供的注册码.Windows和Mac通用. 软件去官网下载安装即可. Registered Name:https://zhile.io License Key: 48891cf209c ...
- 【Noip模拟 20161005】运货
问题描述 小ww开了一家快递公司,在nn个城市之间进行货物运输工作,一共雇了mm个快递员. 每个快递员性格很奇特,第ii号快递员只愿意将货物从城市sisi运送到titi(甚至不愿意将货物 从titi运 ...
- Java遍历树(深度优先+广度优先)
在编程生活中,我们总会遇见树性结构,这几天刚好需要对树形结构操作,就记录下自己的操作方式以及过程.现在假设有一颗这样树,(是不是二叉树都没关系,原理都是一样的) 1.深度优先 英文缩写为DFS即Dep ...
- tensorflow 1.9 ,bazel 0.15.0,源码编ERROR, Skipping, '//tensorflow/tools/pip_package:build_pip_package',error loading packageCuda Configuration Error, Cannot find libdevice.10.bc under /usr/local/cuda-8.0
最近在看tensorflow 移动端部署,需要编译源码才支持,所以又拾起来了编译这项老工作,其中遇到问题: bazel build --cxxopt="-D_GLIBCXX_USE_CXX1 ...
- tesseract编译错误:fatal error: allheaders.h: No such file or directory
错误描述: globaloc.cpp::: fatal error: allheaders.h: No such file or directory #include "allheaders ...
- java文件转发
实际开发情景中,有时会遇到文件需要从一台服务器发到另一台服务器的情况,比如外网发到内网,服务器之间文件同步的情况. 就可以用文件转发. 转发端代码: /** * * @param fileName 保 ...