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 |
怎么转化成二分图亚怎么转化成二分图亚?分为男孩和女孩,我做了,在求最大匹配,但是wa,大家是怎么转化成二分图的? int main() { while( scanf( "%d", &n ) == 1 ) { int a, b[maxn]; map< int, int >im; memset( g, 0, sizeof(g) ); ans = 0; int num; for( int i = 0; i < n; i++ ) { scanf( "%d", &a ); getchar();getchar();getchar(); scanf( "%d", &num ); getchar(); for( int i = 0; i < num; i++ ) { scanf( "%d", &b[i] ); } int flag = 0; for( int i = 0; i < num; i++ ) { if( im[b[i]] > 0 ) { flag = 1; break; } else if( im[b[i]] < 0 ) { flag = -1; break; } } if( im[a] > 0 ) { for( int i = 0; i < num; i++ ) { im[b[i]] = -1; g[a][b[i]] = 1; } } else if( im[a] < 0 ) { for( int i = 0; i < num; i++ ) { im[b[i]] = 1; g[b[i]][a] = 1; } } else if( flag > 0 ) { im[a] = -1; for( int i = 0; i < num; i++ ) { im[b[i]] = 1; g[b[i]][a] = 1; } } else if( flag < 0 ) { im[a] = 1; for( int i = 0; i < num; i++ ) { im[b[i]] = -1; g[a][b[i]] = 1; } } else if( im[a] == 0 && flag == 0 ) { im[a] = 1; for( int i = 0; i < num; i++ ) { im[b[i]] = -1; g[a][b[i]] = 1; } } } //for Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator