【HDU】2860 Regroup 并查集
来源:互联网 发布:mac apache php 编辑:程序博客网 时间:2024/06/16 07:39
传送门:【HDU】2860 Regroup
题目分析:其实就是披着并查集外表的模拟题,照着做就好了。。。话说题目中给了x==y。。这个真的大丈夫?。。
代码如下:
#include <cmath>#include <cstdio>#include <cstring>#include <algorithm>using namespace std ;#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REPV( i , a , b ) for ( int i = a ; i >= b ; -- i )#define clear( a , x ) memset ( a , x , sizeof a )typedef long long LL ;const int MAXN = 100005 ;const LL INF = 1e11 ;int p[MAXN] ;LL rate[MAXN] ;int n , m , k ;char s[5] ;int find ( int x ) {int ans , tmp , o = x ;while ( p[o] != o )o = p[o] ;ans = o ;o = x ;while ( p[o] != o ) {tmp = p[o] ;p[o] = ans ;o = tmp ;}return ans ;}void read ( int &x ) {x = 0 ;char c = ' ' ;while ( c < '0' || c > '9' )c = getchar () ;while ( c >= '0' && c <= '9' ) {x = x * 10 + c - '0' ;c = getchar () ;}}void work () {int newbie , c ;int x , y ;REP ( i , n )p[i] = i , rate[i] = INF ;input () ;REP ( i , m ) {scanf ( "%s" , s ) ;if ( s[0] == 'A' ) {scanf ( "%d%d" , &newbie , &c ) ;if ( c != find ( c ) )printf ( "Reject\n" ) ;else {printf ( "Accept\n" ) ;if ( rate[c] > newbie )rate[c] = newbie ;}}if ( s[0] == 'G' ) {scanf ( "%d" , &c ) ;x = find ( c ) ;if ( x != c )printf ( "Company %d is a part of company %d.\n" , c , x ) ;else if ( rate[c] == INF )printf ( "Company %d is empty.\n" , c ) ;elseprintf ( "Lowest rate: %I64d.\n" , rate[c] ) ;}if ( s[0] == 'M' ) {scanf ( "%d%d" , &x , &y ) ;if ( x != find ( x ) || y != find ( y ) || x == y )printf ( "Reject\n" ) ;else {printf ( "Accept\n" ) ;p[y] = x ;if ( rate[x] > rate[y] )rate[x] = rate[y] ;}}}printf ( "\n" ) ;}int main () {while ( ~scanf ( "%d%d%d" , &n , &k , &m ) )work () ;return 0 ;}
0 0
- 【HDU】2860 Regroup 并查集
- hdu 2860 Regroup【并查集+有道】
- HDU 2860 Regroup(并查集)
- HDU 2860 Regroup(并查集)
- hdu 2860 Regroup 带权并查集
- hdu 2860(并查集应用)
- HDU 3371 并查集
- HDU 2473 并查集
- hdu 1116 并查集
- HDU 1856 并查集
- HDU 1598 并查集
- HDU-1232 并查集
- 【并查集】hdu 2818
- hdu 1232 并查集
- hdu 1856(并查集)
- HDU 1598 并查集
- HDU-1232(并查集)
- hdu 1856 并查集
- (31)DOM应用之搜索表格中的内容(简单搜索)
- Uva 10010-Where's Waldorf?
- 在使用angularjs过程,ng-repeat中track by的作用
- UVA 10177 (暑假-数学(3) -D - (2/3/4)-D Sqr/Rects/Cubes/Boxes?)
- Hadoop 2.4.0 伪分布式环境搭建
- 【HDU】2860 Regroup 并查集
- Android Fragment 真正的完全解析(上)
- u-boot的Makefile分析
- hdoj 1687 Lucky Light 【区间找点】
- Spark1.01运行例子以及问题解决
- [Python]新式类的__slots__属性
- 学习opencv之(六)-图像切割,使用ROI
- C#接口规范
- Ubutun常用命令之mount