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 ...
随机推荐
- windows:plsql配置oracle连接
1.plsql安装 此处省略,后续添加 2.plsql连接oracle: (1) 下载Instant client:http://www.oracle.com/technetwork/cn/topic ...
- <记录> HtmlHelper和 强类型页面
HtmlHelper 路径生成 <!--普通写法--> <a href="/home/index">超链接</a> <!--利用Url类 ...
- MySQL 8.0 新增SQL语法对窗口函数和CTE的支持
尝试了一下MySQL 8.0的部分新特性. 如果用过MSSQL或者是Oracle中的窗口函数(Oracle中叫分析函数), 然后再使用MySQL 8.0之前的时候,就知道需要在使用窗口函数处理逻辑的痛 ...
- jscript DOM操作
\n 换行符 \b 空格 \r 回车 && 与 || 或 ! 非(取反) classList属性 classList 属性返回元素的类名,作为 DOMTokenList 对象. 该属性 ...
- canvas刮刮乐游戏等
裁剪 ctx.clip():当前路径外的区域不再绘制 <canvas id="cans" width=500 height=500></canvas> &l ...
- php的pid文件指定用户
比如pid文件指定www用户,首先得有这用户和用户组. 找到pathtophp-fpm.conf文件,修改里面得相关内容. 修改listen.owner=www listen.group=www us ...
- java学习笔记(九):Java 流(Stream)、文件(File)和IO
Java 的控制台输入由 System.in 完成. 为了获得一个绑定到控制台的字符流,你可以把 System.in 包装在一个 BufferedReader 对象中来创建一个字符流.需要import ...
- c++ 面试题(算法类)
1,从无序的数据流中找到其中位数:(用大根堆和小根堆来实现) float getMidimum(vector<int>& nums) { priority_queue<int ...
- 187. Repeated DNA Sequences重复的DNA子串序列
[抄题]: All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: &qu ...
- php Pthread 线程 互斥锁
在进行并发操作时,会导致共享数据的完整性的问题,要加入锁,在任意时刻只有一个线程访问该对象在PHP中定义专门用于线程同步控制的mutex的函数, pthreads v3 中已经将 Mutex 类移除. ...