- 并查集
- 题意:找出给定的这些话中是否有冲突。若没有则最多有多少句是对的。
并查集
题意:找出给定的这些话中是否有冲突。若没有则最多有多少句是对的。
-
-
-
-
-
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- using namespace std;
- typedef long long int64;
-
- typedef pair PII;
- #define MP(a,b) make_pair((a),(b))
- const int maxn = 2005;
- const int inf = 0x7fffffff;
- const double pi=acos(-1.0);
- const double eps = 1e-8;
-
- int fa[ maxn ];
- int rank[ maxn ];
- struct Edge{
- int u,v,next;
- }edge[ maxn<<1 ];
- int cnt,head[ maxn ];
- int vis[ maxn ];
- int Cnt_true,Cnt_false;
-
- void init( int n ){
- cnt = 0;
-
- memset( head,-1,sizeof( head ) ) ;
- for( int i=1;i<=n;i++ ){
- fa[ i ] = i;
- rank[ i ] = 1;
- vis[ i ] = 0;
- }
- }
-
- void addedge( int a,int b ){
- edge[ cnt ].u = a;
- edge[ cnt ].v = b;
- edge[ cnt ].next = head[ a ];
- head[ a ] = cnt ++ ;
-
- edge[ cnt ].u = b;
- edge[ cnt ].v = a;
- edge[ cnt ].next = head[ b ];
- head[ b ] = cnt ++ ;
- }
-
- int find( int x ){
- if( x==fa[x] )
- return