Results 1 to 12 of 12
Thread: C++
Hybrid View
-
15th January 2006 14:29 #1Registered User
Join Date: Jan:2006
Location: sofia
Posts: 5
C++
, .
: , , .
, .
-
15th January 2006 18:53 #2
., : , 0.
Breadth-First Search, , . "" - .
. 4 . .
, , ., . .
"640K ught to be enough for anybody" - Bill Gates, 1981
::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel
-
16th January 2006 14:52 #3Registered 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;
}
-
16th January 2006 15:28 #4
, / .
I mourn thee by dusk | I mourn thee by dawn
Crave for thy gloss | to seek the silent glades beyond
-
16th January 2006 17:22 #5Registered User
Join Date: Jan:2006
Location: sofia
Posts: 5
C++, , . C++ .
-
16th January 2006 22:30 #6Registered User
Join Date: Jun:2005
Location:
Posts: 32
, . , ...




Reply With Quote
Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in