CodeForces 755CPolandBall and Forest
来源:互联网 发布:java borderlayout 编辑:程序博客网 时间:2024/06/06 00:18
题意:
给出第I点到第p i点是最远的,询问有多少个区域。
思路
简单并查集一遍成!
#include <iostream>#include <stdio.h>#include <cstring>using namespace std;#define maxn 100005int father[maxn];int find(int x){ if(father[x]!=x) father[x]=find(father[x]); return father[x];}void Union(int x,int y){ int root1=find(x); int root2=find(y); if(root1!=root2) { father[root1]=root2; } return ;}int main(){ int n; cin>>n; for(int i=1;i<=n;i++) { father[i]=i; } for(int i=1;i<=n;i++) { int t; cin>>t; Union(t,i); } int ans=0; for(int i=1;i<=n;i++) { if(father[i]==i) { ans++; } } cout<<ans<<endl;}
0 0
- CodeForces 755CPolandBall and Forest
- 【codeforces 755C】PolandBall and Forest
- Codeforces 755C-PolandBall and Forest
- CodeForces 755C PolandBall and Forest
- Misha and Forest CodeForces
- Codeforces 755-C. PolandBall and Forest(交互式题)
- 【Codeforces 755 C PolandBall and Forest】+ 并查集
- CodeForces 501C Misha and Forest
- Codeforces 501C - Misha and Forest (机智)
- Codeforces Round #285 C. Misha and Forest
- codeforces round 285 div285 Misha and Forest
- 【codeforces 501 C Misha and Forest】
- CodeForces 501C Misha and Forest
- codeforces 501 C. Misha and Forest (思维)
- codeforces 501C Misha and Forest(思维题)
- Codeforces Round #285 (Div. 2) C. Misha and Forest
- Codeforces Round #285 (Div. 2) C - Misha and Forest
- Codeforces #285 C Misha and Forest 队列维护 解题报告
- hdu 1800
- maven 本地仓库存在jar包但是项目依旧提示 Failed to read artifact XXX missing artifact XXX的问题
- learnyounode学习笔记(一)
- android UiAutomator一个完整的个人信息修改测试用例
- Excel与Java时间问题:
- CodeForces 755CPolandBall and Forest
- Zbar算法流程介绍
- java基础
- ListView和GridView重复调用getView的解决方法
- Linux中$@,$#,$0,$1,$2的含义
- JVM性能调优监控工具jps、jstack、jmap、jhat、jstat、hprof使用详解
- js和html结合的判断、循环语句
- 关于机器学习的领悟与反思
- <意志的力量>我的思考