615 - Is It A Tree?

All about problems in Volume 6. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

waqascs
New poster
Posts: 1
Joined: Sun Jun 03, 2012 4:19 pm

Re: 615 - Is It A Tree?

Post by waqascs »

my code is below ..do not why it gets WA :oops:
#include<iostream>
using namespace std;
int count=0;
int temp=0;
int main ()
{
int a[100]; //Source array
int b[100]; //Destination array
int l=0,p=0,k=0,c;
char u;
cout<<"Enter root value:";
cin>>a[0]; //setting the root
cout<<endl;
//==============================Input Block==============
while(k<100)
{
for(static int i=0;i<=k;i++)
{
cout<<"Enter source:"<<endl;
cin>>a;
}
for(static int j=0;j<=k;j++)
{
cout<<"Enter destination:"<<endl;
cin>>b[j];
}
cout<<"want to enter more node press 'y' or check is it a tree press 'N'!"<<endl;
cin>>u;
if(u=='Y' || u=='y')
{
k++;
}
else
{
k=101;

}
}

//=============================basic logic of finding , is it a tree !!===========//
while(l<100)
{ temp=b[l];
for(p=0;p<100;p++)
{
if(count<2)
{
if(temp==b[p])
{
count++;
}
}
else
{
p=101;
l=101;
}

}
if(count==2)
{
l=101;
}
else
{
count=0;
l++;
}
}
if(count>=2)
{
cout<<"it is not a tree!"<<endl;
}
else
{
cout<<"it is a tree!"<<endl;
}


return 0;
}
help me out guys!!
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 615 - Is It A Tree?

Post by brianfry713 »

"Enter root value:" should not be in the output.
Check input and AC output for thousands of problems on uDebug!
umer naseer
New poster
Posts: 1
Joined: Thu Dec 27, 2012 1:17 pm

615 it is a tree

Post by umer naseer »

plz help me to find out how my answer is wrong


// IsItATree.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
using namespace std;
int count=0;
int temp=0;
int _tmain(int argc, _TCHAR* argv[])
{
int a[100];
int b[100];
int l=0,k=0;
char u;

while(k<100)
{
for(static int i=0;i<=k;i++)
{
cout<<"Enter source:"<<endl;
cin>>a;
}
for(static int j=0;j<=k;j++)
{
cout<<"Enter destination:"<<endl;
cin>>b[j];
}
cout<<"want to enter more node press 'y' or check is it a tree press 'N'!"<<endl;
cin>>u;
if(u=='Y' || u=='y')
{
k++;
}
else
{
k=100;

}
}

//=============================basic logic of finding , is it a tree !!===========//
while(l<100)
{ temp=b[l];
for(static int p=0;p<5;p++)
{
if(count<2)
{
if(temp==b[p])
{
count++;
}
}
else
{
p=100;
l=100;
}

}
if(count==2)
{
l=100;
}
else
{
count=0;
l++;
}
}
if(count>=2)
{
cout<<"|=====================|"<<endl;
cout<<"| it is not a tree! |"<<endl;
cout<<"|=====================|"<<endl;

}
else
{
cout<<"|=====================|"<<endl;
cout<<"| it is a tree! |"<<endl;
cout<<"|=====================|"<<endl;

}
return 0;

}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 615 it is a tree

Post by brianfry713 »

don't use stdafx.h
doesn't match the sample I/O
Check input and AC output for thousands of problems on uDebug!
triplemzim
New poster
Posts: 48
Joined: Sat Apr 06, 2013 6:02 pm

Re: 615 - Is It A Tree?

Post by triplemzim »

For those who are getting WA::
If there is no node then it is a tree.... so

for test case:
input:

Code: Select all

0 0 -1 -1
output:

Code: Select all

Case 1 is a tree.
csprajeeth
New poster
Posts: 5
Joined: Sat May 26, 2012 7:25 pm

Re: 615 - Is It A Tree?

Post by csprajeeth »

Some corner cases.

INPUT

Code: Select all

6 8  5 3  5 2  6 4
5 6  0 0

6 8  5 3  5 2  6 4
5 6  5 3 0 0

8 1  7 3  6 2  8 9  7 5
7 4  7 8  7 6  0 0

3 8  6 8  6 4
5 3  5 6  5 2  0 0

1 2 3 3 0 0

99006 700002 700002 880002  880002 1000001 1000001 1234567890 1234567890 22 0 0
0 0
-1 -1
OUTPUT

Code: Select all

Case 1 is a tree.
Case 2 is not a tree.
Case 3 is a tree.
Case 4 is not a tree.
Case 5 is not a tree.
Case 6 is a tree.
Case 7 is a tree.
Aarya
New poster
Posts: 8
Joined: Thu Nov 21, 2013 6:05 pm

Re: 615 - Is It A Tree?

Post by Aarya »

Input:

Code: Select all

1 2
2 3
4 3
2 4
0 0

1 2
2 3
4 5
0 0

1 7346537
37542 1
0 0

7 7
0 0

8 9
0 5
0 0

100 1
1 2
9 7
7 3
3 88
88 6
1 9
2 6
0 0

1 2
1 2
0 0

999999 5
0 0

0 0

-1 -1
Output:

Code: Select all

Case 1 is not a tree.
Case 2 is not a tree.
Case 3 is a tree.
Case 4 is not a tree.
Case 5 is not a tree.
Case 6 is not a tree.
Case 7 is not a tree.
Case 8 is a tree.
Case 9 is a tree.

Repon kumar Roy
Learning poster
Posts: 96
Joined: Tue Apr 23, 2013 12:54 pm

Re: 615 - Is It A Tree?

Post by Repon kumar Roy »

Got AC :)
Be careful about period after tree.
Series of WA for that

Again Thanks brain fry
Last edited by Repon kumar Roy on Tue Dec 02, 2014 11:38 pm, edited 1 time in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 615 - Is It A Tree?

Post by brianfry713 »

Change:
if( node ==0 ){
printf("Case %d is a tree\n",++cs);
to:
if( node ==0 ){
printf("Case %d is a tree.\n",++cs);

You are missing the period.
Check input and AC output for thousands of problems on uDebug!
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 615 - Is It A Tree?

Post by lighted »

There can be repeated edges and node can point to itself.
xenon wrote:I had my program rejected after rejudge too, but got AC after adjusting for bigger input (no. of nodes 10000 -> 100000).
xenon wrote:Sorry, I was referring to the maximum nodenumber. I don't know about the maximum number of nodes, but it could of course be also increased to above 100.
I don't use a matrix to store edges, so I can't tell.
My code accepted with number of different nodes = 15. Maximum value of node number is 50000.
Red Scorpion wrote:input:
1 2
1
4 5
0 0

output:
Case 1 is not a tree.
This input is invalid.

Problem description says
Node numbers will always be greater than zero.
5th case of Aarya's input is invalid.

Code: Select all

8 9
0 5
0 0
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
uradura
New poster
Posts: 11
Joined: Thu Jan 01, 2015 10:31 am

Re: 615 - Is It A Tree?

Post by uradura »

http://ideone.com/7bNsHQ :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops:
why wrong answer????
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 615 - Is It A Tree?

Post by brianfry713 »

It looks like you figured it out.
Check input and AC output for thousands of problems on uDebug!
Post Reply

Return to “Volume 6 (600-699)”