Saratov State University :: Online Contester


::Go
- home
- news
- register
- update personal info
- problemset archive
- submit
- status online
- standing
- contests
- virtual contests
- forum
- statistic
- FAQ
- links
- projects

::Poll
Are you registered on Codeforces?
Yes
No
What is it???

[results]

::webboard

why i am PE on test 6
Author: zyt
ID: 045102
Problem: 122
Contest: 0
Date: 2012-01-15 10:34:24

this is my code:
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define SIZE 1010
bool mat[ SIZE ][ SIZE ];
bool vis[ SIZE ];
int ans[ SIZE ];
int temp[ SIZE ];
int cnt;
int n;

void Init(){
cnt = 1;
memset( vis, false, sizeof( vis ) );
memset( mat, false, sizeof( mat ) );
}

char buffer[ 5001 ], *token;
char rbuf[ 5001 ];

void Input(){


// gets(rbuf); sscanf(rbuf,"%d",&n);
scanf( "%d", &n );
getchar();

for ( int u = 1; u <= n; ++ u ){
gets( buffer );
token = strtok( buffer, " ");

while ( token != NULL ){
int x = atoi( token );
mat[ u ][ x ] = mat[ x ][ u ] = true;
token = strtok( NULL, " ");
}
}

}

int find( int num ){
for ( int i = 1; i <= cnt; ++ i )
if ( ans[ i ] == num )
return i;
}

void Xchg( int from, int to ){

int pos = find( from );
for ( int i = 1; i <= cnt; ++ i )
temp[ i ] = ans[ ( i + pos ) > cnt ? ( i +pos - cnt ) : ( i + pos ) ];

for ( int i = 1; i <= cnt; ++ i )
ans[ i ] = temp[ i ];

ans[ ++cnt ] = to;
}

void Cal(){

ans[ 1 ] = 1;
vis[ 1 ] = true;

int End = 1;

while ( End <= n ){
if ( !vis[ End ] && mat[ ans[ cnt ] ][ End ] ){
ans[ ++cnt ] = End;
vis[ End ] = true;
End = 1;

}
else
End++;
}


part1:
if ( mat[ ans[ 1 ] ][ ans[cnt] ] ){
if ( cnt == n ){
ans[ ++ cnt ] = 1;
return ;
}else{
for ( int from = 1; from <= n; ++from ) if ( vis[ from ] )
for ( int to = 1; to <= n; ++ to ){
if ( !vis[ to ] ){
if ( mat[ from ][ to ] ){
vis[ to ] = true;
Xchg( from, to );
}
}
}
goto part1;
}
}

else{
for ( int poss = 3; poss <= cnt - 1; ++ poss ){
if ( mat[ ans[1] ][ ans[ poss ] ] && mat[ ans[ poss - 1 ] ][ ans[cnt] ] ){

for( int s = poss; s <= cnt; ++ s )
temp[ s ] = ans[ s ];

for( int s = poss; s <= cnt; ++ s )
ans[ cnt + poss - s ] = temp[ s ];
goto part1;
}
}
}
}

void Output(){
int pos = find( 1 );
for ( int i = 1; i <= cnt; ++ i ){
if ( i != 1 )
printf( " " );
printf( "%d", ans[ ( i + pos - 1 ) > cnt ? ( i + pos - 1 - cnt ) : ( i + pos - 1 ) ] );
}
printf("n");
}

int main(){

Init();
Input();
Cal();
Output();

return 0;
}
/*
4
2 3
1 4
1 4
2 3
*/

see sub-tree reply to that message


::Login
Forgot password?

::News
22.10.12 - The problems from the Southern Subregional Programming Contest 2012 added to the problemset archive (542 - 553).
22.10.12 - After the start of the contest the statements in PDF will be available by the link.
23.10.11 - The problems from the Southern Subregional Programming Contest 2011 added to the problemset archive (530 - 541).

::Counter

Server time: 2017-09-22 21:05:10Online Contester Team © 2002 - 2016. All rights reserved.