ural Graph Decomposition

呃,题目是不长,但是太难理解了,不知道present还有分解的意思,看了discuss里的各种猜,还是没弄懂,最后看了解题报告,就一句话,每次删除连通分支里相邻的两条边,问最后能否全部删除完。呃,思路也很简单,如果每个连通分支里的边都为偶数则输出1,否则输出0.用并查集来实现。

代码:

View Code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <vector>
#include <stack>
#define  N 1004
#define  INF 1000000000
using namespace std ;

int num[N] , f[N] ;

void init()
{
    memset( num , 0 , sizeof ( num )) ;
    for ( int i = 0 ; i < N ; i++ )
    f[i] = i ;
}

int find( int x )
{
    if ( x != f[x] )
    f[x] = find( f[x] ) ;
    return f[x] ;
}

int main()
{
    int x , y , a , b ;
    init() ;
    while ( scanf ( "%d%d" , &x , &y ) != EOF )
    {
        a = find( x ) ;
        b = find( y ) ;
        if ( a != b )
        {
            f[b] = a ;
            num[a] += num[b] ;
        }
        ++num[a];
        //cout<<num[a]<<endl ;
    }
    bool flag = true ;
    for ( int i = 1 ; i < N ; i++ )
    if ( f[i] == i && num[i] % 2 )
    {
        flag = false ;
        break ;
    }
    if( flag )
    printf( "1\n" ) ;
    else
    printf( "0\n" ) ;
    return 0 ;
}

 

转载于:https://www.cnblogs.com/misty1/archive/2013/01/29/2880830.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值