Moderator: Board moderators

20 0
0 0
dfs()
for each person ,
assume he is speaking truth,
-> All reliables are speaking truth
dfs(for each reliable)
if he is false
do nothing.

As an example, let's assume there are four informants A, B, C and D, with the following surveyed answers: ``A says B is reliable but D is not'', ``B says C is not reliable'', and ``C says A and D are reliable''. In this case, it happens that at most two informants are reliable.

tryit1 wrote:As an example, let's assume there are four informants A, B, C and D, with the following surveyed answers: ``A says B is reliable but D is not'', ``B says C is not reliable'', and ``C says A and D are reliable''. In this case, it happens that at most two informants are reliable.
Can you tell me how we get 2 informans as reliable ? how would you approach the above example. Any similar problems ?
Ithink it is a easy problem
But I got WA........![]()
![]()
Some one PLZ check my code.........
#include<stdio.h>
#include<stdlib.h>
int a[803];
int main()
{
int i,n,b,c,m,Count,j,d;
while(scanf("%d%d",&m,&n)==2 && (m || n))
{
Count= 0;
for(i=1;i<=m;i++)
a[i]=1;
for(i=1;i<=n;i++)
{
scanf("%d%d",&b,&c);
if(a[b])
{
if( c > 0)
{
a[c] = 1;
}
else if(c < 0)
{
d = (-1)*c;
a[d] = 0;
}
}
}
for(i=1;i<=m;i++)
{
if(a[i])
Count++;
}
printf("%d\n",Count);
}
return 0;
}
20 6
1 -3
2 -3
3 1
2 2
7 -1
4 3
Thanks hasan3050 for ur test case
I solve this test case But again WA
My modified code Here:
PLZ help me.....
#include<stdio.h>
#include<stdlib.h>
int a[803];
int main()
{
int i,n,b,c,m,Count,d,e;
//freopen("a.txt","r",stdin);
while(scanf("%d%d",&m,&n)==2 && (m || n))
{
Count= 0;
for(i=1;i<=m;i++)
a[i]=1;
for(i=1;i<=n;i++)
{
scanf("%d%d",&b,&c);
e = c;
if( e < 0)
{
e = (-1)*e;
}
if( (a[b]==2) && ( a[e] > 0) )
{
if( c > 0)
{
a[c] = 2;
}
else if(c < 0)
{
a[e] = 0;
}
}
else if( (a[b]==1) && ( a[e] > 0) )
{
if( c > 0)
{
a[c] = 2;
}
else if(c < 0)
{
a[e] = 0;
}
}
}
for(i=1;i<=m;i++)
{
//printf("a [%d] == %d\n",i,a[i]);
if(a[i]>=1)
Count++;
}
printf("\n%d\n",Count);
}
return 0;
}
3 2
1 -3
3 -2
0 0
Igor9669 wrote:First you print leading new line!
Second why do you use such a big array you need only 20 elements and third try this test:
- Code: Select all
3 2
1 -3
3 -2
0 0
Answer should be 1!
keep dreaming...Jehad Uddin wrote:because 3 isnt reliable and 2 isnt reliable ,so only 1 is reliable so ans is 1,its so simple problem,try all the I/Os in the board,![]()
![]()
Users browsing this forum: No registered users and 0 guests