Page 1 of 2

11690

Posted: Tue Oct 06, 2009 5:54 pm
by durjay
I solve the this problem by DFS. but it is time limit exceed. here is my code:

#include<stdio.h>

long int k1;

long int g[10001][10001]={0},cl[10001];

long int d,cu[10001];

int dfs();

void dfs_visit(int u);

int main()

{

long int u,r,j,a,y;

long int c,s,i,t;

scanf("%ld",&t);

for(i=1;i<=t;i++)

{



scanf("%ld%ld",&u,&r);

d=u;

for(j=0;j<u;j++)

scanf("%ld",&cu[j]);



for(j=0;j<r;j++)

{

scanf("%ld%ld",&a,&y);

g[a][y]=1;

g[y][a]=1;

}

r=dfs();

if(r==0)

printf("IMPOSSIBLE\n");

else

printf("POSSIBLE\n");

for(c=0;c<d;c++)

for(s=0;s<d;s++)

g[c][s]=0;

}

return 0;

}

int dfs()

{



int i;

for(i=0;i<d;i++)

{

cl=1;

}

for(i=0;i<d;i++)

{

if(cl==1)

{

k1=0;

k1=k1+cu;

dfs_visit(i);

if(k1<0)

{

return 0;

break;

}

}

}

return 1;

}



void dfs_visit(int u)

{

int i;

cl=2;



for(i=0;i<d;i++)

{

if(g==1)

{

if(cl==1)

{

k1=k1+cu;

dfs_visit(i);

}

}

}

cl=3;



}

plz help me.

11690 - Money Matters

Posted: Tue Oct 06, 2009 6:02 pm
by durjay
accepted

Re: 11690 MONEY MATTERS

Posted: Tue Oct 06, 2009 6:26 pm
by Igor9669
You use a lot of memory(about 400 MB), your solution wouldn't work!

Re: 11690 MONEY MATTERS

Posted: Tue Oct 06, 2009 8:37 pm
by saiful_sust
Hi durjay...
Try to solve it with set operation ..............
it is a easy problem..............
Always think easy.........

Re: 11690 MONEY MATTERS

Posted: Tue Oct 06, 2009 9:33 pm
by arifcsecu
Durjoy
Try to use Vector
i got it accepted using vector

Re: 11690 MONEY MATTERS

Posted: Wed Oct 07, 2009 6:09 pm
by saiful_sust
Durjoy
try it with set operation

u have to find disjoin set and total sum of every set = 0 than it is possible
else impossible

EX: if 1 and 2 is friend, 3 and 4 is friend than there is two set.

but when 2 and 3 is friend than there is 1 set that is {1,2,3};

I think that is enough.............
try it ..... :D

Re: 11690 MONEY MATTERS

Posted: Wed Oct 14, 2009 7:43 pm
by arifcsecu
Durjoy
remove ur code if u got accepted

Re: 11690 MONEY MATTERS

Posted: Thu Oct 22, 2009 7:18 am
by poixp
The solution with matrix also works if you chose the correct data type. Long int is overhead.

Re: 11690 MONEY MATTERS

Posted: Thu Nov 12, 2009 10:28 pm
by Taman
Thanks to Arifcsecu. . .ur reply to Durjay helped me a lot. . . :D

Re: 11690 MONEY MATTERS

Posted: Fri Nov 13, 2009 3:31 pm
by arifcsecu
Taman wrote:Thanks to Arifcsecu. . .ur reply to Durjay helped me a lot. . . :D
It is OK

Re: 11690 MONEY MATTERS

Posted: Wed Dec 05, 2012 9:49 am
by brianfry713
Input:

Code: Select all

1
5 4
1
1
1
1
-4
0 1
2 3
1 2
3 4
AC output POSSIBLE

Re: 11690 MONEY MATTERS

Posted: Fri Sep 06, 2013 2:43 pm
by moxlotus
Accepted.

Re: 11690 MONEY MATTERS

Posted: Fri Sep 06, 2013 10:43 pm
by brianfry713
Use class Main

Re: 11690 MONEY MATTERS

Posted: Sat Sep 07, 2013 4:24 pm
by moxlotus
My submitted code is using Main. still it didnt work. =(
Do u have any other test cases to help me out ? Thanks
brianfry713 wrote:Use class Main

Re: 11690 MONEY MATTERS

Posted: Mon Sep 09, 2013 11:42 pm
by brianfry713
Remove line 72:
count --;