Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我用rank之间的差来说明是否可能是相同的,可是一直WA!#include <iostream> #include <cmath> using namespace std; const int SIZE = 100001; int rank[SIZE], p[SIZE]; int n; int findset ( int x ) { if ( x != p[x] ) p[x] = findset ( p[x] ); return p[x]; } void eunion( int x, int y ) { x = findset ( x ); y = findset ( y ); if ( rank[x] > rank[y] ) p[y] = x; else { p[x] = y; if ( rank[y] == rank[x] ) rank[y]++; } } int main() { int test, m, s, t; char c; // freopen ( "1703.txt", "r", stdin ); for ( scanf ( "%d", &test ); test > 0; test-- ) { scanf ( "%d%d", &n, &m ); for ( s = 1; s <= n; s++ ) { rank[s] = 0; p[s] = s; } for ( int i = 0; i < m; i++ ) { getchar(); scanf ( "%c%d%d", &c, &s, &t ); if ( c == 'A' ) { int x = findset ( s ), y = findset ( t ); if ( x != y ) puts ( "Not sure yet." ); else { if ( abs ( rank[s] - rank[t] ) % 2 != 0 ) puts ( "In different gangs." ); else puts ( "In the same gang." ); } } else eunion ( s, t ); } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator