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. java 性能测试框架工具-junitperf

    性能测试工具 对于 Java 开发者来说,要去学习性能测试工具未免很麻烦. 但有时候会有性能测试的需求. junitperf junitperf 就是一款为 Java 开发者设计的性能测试框架,如果你 ...

  2. File mapping

    文件映射的三个功能: 1.File mapping allows the process to use both random input and output (I/O) and sequentia ...

  3. issue_hana

    2019-01-11T14:35:01.910187+08:00 SHADEVDB01 cron[57062]: PAM unable to dlopen(/lib64/security/pam_sy ...

  4. cat查阅文件技巧

    一.打印除匹配行之外的其它行,使用-v 打印除$和#的注释行:cat file| grep -v ^$ | grep -v ^#

  5. leetcode121

    public class Solution { public int MaxProfit(int[] prices) { //寻找最优极值点(包括2个端点) ) { ; } ) { ] - price ...

  6. EasyARM-iMX283A的U盘使用教程

    在编写代码前我们先来EasyARM-iMX283A对U盘使用的操作. 我们先拿一个U盘进行格式化 在U盘中写一些文件保存后,弹出U盘. 将U盘插入EasyARM-iMX283A的开发板. [注意]Ea ...

  7. MySQL统计信息以及执行计划预估方式初探

    数据库中的统计信息在不同(精确)程度上描述了表中数据的分布情况,执行计划通过统计信息获取符合查询条件的数据大小(行数),来指导执行计划的生成.在以Oracle和SQLServer为代表的商业数据库,和 ...

  8. javascript函数嵌套时arguments的问题

    疑问: var funtest = function () { var fun = function (val, val2) { alert(arguments.length); //此处答案? 有些 ...

  9. 深入理解Java中的IO

    深入理解Java中的IO 引言:     对程序语言的设计者来说,创建一个好的输入/输出(I/O)系统是一项艰难的任务 < Thinking in Java >   本文的目录视图如下: ...

  10. day37 异步回调和协程

    异步回调 """ 异步任务使用场景 爬虫 1.从目标站点下载网页数据 本质就是HTML格式字符串 2.用re从字符串中提取出你需要的数据 ""&quo ...