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(基础并查集)的更多相关文章

  1. Codeforces Round #541 F. Asya And Kittens

    题面: 传送门 题目描述: Asya把N只(从1-N编号)放到笼子里面,笼子是由一行N个隔间组成.两个相邻的隔间有一个隔板. Asya每天观察到有一对想一起玩,然后就会把相邻的隔间中的隔板取出来,使两 ...

  2. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  3. 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 ...

  4. Educational Codeforces Round 14 D. Swaps in Permutation(并查集)

    题目链接:http://codeforces.com/contest/691/problem/D 题意: 题目给出一段序列,和m条关系,你可以无限次互相交换这m条关系 ,问这条序列字典序最大可以为多少 ...

  5. 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 ...

  6. Codeforces Round #345 (Div. 1) E. Clockwork Bomb 并查集

    E. Clockwork Bomb 题目连接: http://www.codeforces.com/contest/650/problem/E Description My name is James ...

  7. Codeforces Round #345 (Div. 2) E. Table Compression 并查集

    E. Table Compression 题目连接: http://www.codeforces.com/contest/651/problem/E Description Little Petya ...

  8. 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, ...

  9. 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 ...

随机推荐

  1. SpringMVC 启动流程

    首先看一下Web应用部署初始化过程 (Web Application Deployement),官方文档说明: Web Application Deployment When a web applic ...

  2. Java内存泄漏定位

    Java虚拟机内存分为五个区域:方法区,堆,虚拟机栈,本地方法栈,程序计数器.其中方法区和堆是java虚拟机共享的内存区域,虚拟机栈,本地方法栈,程序计数器是线程私有的. 程序计数器(Program ...

  3. IntelliJ IDEA 性能优化

    idea打开的多了 内存占用也就多了 下边是亲试的优化ide性能的方法 1.设置JVM的启动参数: 进入idea的安装目录的bin文件夹 打开 idea.exe.vmoptions 文件, 修改-Xm ...

  4. jQuery入门基础(动画效果)

    一.隐藏显示 1.show()--显示隐藏的被选择元素 例:$(selector).show(speed,callback); 2.hide()--隐藏被选元素的内容 例:$(selector).hi ...

  5. 转载:oracle 启动过程--oracle深入研究

    Oracle数据库的启动-nomount状态深入解析 通常所说的Oracle Server主要由两个部分组成:Instance和Database.Instance是指一组后台进程(在Windows上是 ...

  6. IIC 设备使用

    通过 读 / 写 IIC 设备上特定的存储空间,来使用设备提供的功能: 存储空间地址 = 设备名 + 设备地址(Slave Address) + 寄存器地址 . 注:设备地址.寄存器地址.地址中写入数 ...

  7. 第二篇*1、Python基本数据类型

    数据类型: 变量可以处理不同类型的值,基本的类型是数和字符串.使用变量时只需要给它们赋一个值.不需要声明或定义数据类型.Python3 中有六个标准的数据类型:Number(数字),String(字符 ...

  8. Unity 获取指定资源目录下的所有文件

    string path="Assets";//Assets/Scenes if(Directory.Exists(path)){ var dirctory=new Director ...

  9. jQuery formValidator API

    jQuery formValidator插件的API帮助 目前支持5种大的校验方式,分别是:inputValidator(针对input.textarea.select控件的字符长度.值范围.选择个数 ...

  10. 多层josn数据 修改

    var aa = { a: 1, b: { c: 1, d: 1 }, e: [{ f: 1, g: 2 }, { h: 1, i: { j: 3, k: [{ l: 55, m: [1, 2, 3, ...