Results 1 to 12 of 12

Thread: C++

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date: Jan:2006
    Location: sofia
    Posts: 5

    C++

    , .
    : , , .

    , .

  2. #2
    ɐ-əpoɔᴉu⋂ ɐ ə anrieff's Avatar
    Join Date: Apr:2004
    Location: Sofia
    Posts: 8,448
    ., : , 0.
    Breadth-First Search, , . "" - .
    . 4 . .

    , , .
    , . .
    "640K ught to be enough for anybody" - Bill Gates, 1981
    ::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel

  3. #3
    Registered User
    Join Date: Jan:2006
    Location: sofia
    Posts: 5
    , . :

    #include <stdio.h>

    #define MAX 100

    #define NONE -1
    #define RED 0
    #define BLUE 1

    int neigh[MAX][MAX], neigh_n[MAX];
    int color[MAX];
    int n;
    int queue[MAX];
    int r, w;

    int main( void )
    {
    int i, j;

    freopen( "twoc.c", "r", stdin );

    scanf( "%*s%d", &n );
    for( i = 1; i <= n; neigh_n[i++] = j )
    for( j = neigh_n[i];; j++ )
    {
    scanf( "%d", &neigh[i][j] );
    if( !neigh[i][j] ) break;
    neigh[ neigh[i][j] ][ neigh_n[neigh[i][j]]++ ] = i;
    }
    for( i = 2; i <= n; color[i++] = -1 );
    queue[0] = 1, r = 0, w = 1;

    for( r = 0; r != w; r++ )
    for( j = 0; j < neigh_n[queue[r]]; j++ )
    if( color[ neigh[queue[r]][j] ] < 0 )
    color[ neigh[queue[r]][j] ] = 1 - color[queue[r]],
    queue[w++] = neigh[queue[r]][j];
    else if( color[ neigh[queue[r]][j] ] == color[queue[r]] )
    {
    printf( "-1" );
    return 0;
    }

    for( i = 1; i <= n; printf( "%d", color[i++] ));

    return 0;
    }

  4. #4
    Executor Lan's Avatar
    Join Date: Nov:2005
    Location:
    Posts: 3,304
    , / .
    I mourn thee by dusk | I mourn thee by dawn
    Crave for thy gloss | to seek the silent glades beyond

  5. #5
    Registered User
    Join Date: Jan:2006
    Location: sofia
    Posts: 5
    C++, , . C++ .

  6. #6
    Registered User
    Join Date: Jun:2005
    Location:
    Posts: 32

    , . , ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |