history
来源:互联网 发布:无锡网络教育学历 编辑:程序博客网 时间:2024/04/28 10:05
并查集
记录每一条边上的时间
因为不能路径压缩
合并的时候把小的合并到大的上来节省时间
好像是叫按秩合并
#include<iostream>#include<cstring>#include<algorithm>#include<cstdio>#include<queue>#include<vector>#include<climits>#include<string>#include<cstdlib>#include<ctime>#define MOD 1000000007#define LL long longusing namespace std;int n,m,i,f[300005],size[300005],c,angry,yr,year[300005],x,y,t,a,b;char p[5];int find(int s,int ti){ while(s!=f[s]&&year[s]<=ti) s=f[s]; return s;}int main(){ scanf("%d%d",&n,&m); for(i=0;i<n;i++) { f[i]=i; size[i]=1; } while(m--) { scanf("%s",p); if(p[0]=='K') { scanf("%d",&c); angry=0; } if(p[0]=='R') { scanf("%d%d",&a,&b); if(angry) { a=(a+c)%n; b=(b+c)%n; } yr++; a=find(a,yr); b=find(b,yr); if(a!=b) { if(size[a]<size[b]) { f[a]=b; size[b]+=size[a]; year[a]=yr; } else { f[b]=a; size[a]+=size[b]; year[b]=yr; } } } if(p[0]=='T') { scanf("%d%d%d",&x,&y,&t); if(angry=((find(x, yr-t)==find(y, yr-t))||(find(x, yr)^find(y, yr)))) printf("N\n"); else printf("Y\n"); } } return 0;}
阅读全文
0 0
- history
- history
- history
- history
- history
- history
- history
- history
- history
- history
- history
- history !
- history
- history
- History
- history
- history
- history.go(),history.back(),history.forward()
- python基础第五篇
- 2017京东校招笔试编程题--python
- 恩智浦杯(飞思卡尔)全国大学生智能车竞赛摄像头简单的图像失真矫正技术原理与实现(透视变换)
- c++初始化列表
- [LeetCode] Binary Tree Postorder题解
- history
- RecycleView在addItemDecoration之后每次重新加载这个页面的时候,item之间的间距都会不断变大大概是变大一倍
- SecureCRT连接(内网和外网)虚拟机中的Linux系统(Ubuntu)
- ModuleNotFoundError: No module named 'mysite'
- 【学习笔记】几个主流云服务商服务简要比对
- 秒杀系统架构分析与实战 for java
- Java写了两个奇怪的线程
- 【反序表+DP】51Nod 1020 逆序排列
- key_values