Page 5 of 5
Re: 615 - Is It A Tree?
Posted: Sun Jun 03, 2012 4:39 pm
by waqascs
my code is below ..do not why it gets WA
#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!!
Re: 615 - Is It A Tree?
Posted: Mon Jun 04, 2012 10:52 pm
by brianfry713
"Enter root value:" should not be in the output.
615 it is a tree
Posted: Thu Dec 27, 2012 1:20 pm
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;
}
Re: 615 it is a tree
Posted: Sat Dec 29, 2012 12:16 pm
by brianfry713
don't use stdafx.h
doesn't match the sample I/O
Re: 615 - Is It A Tree?
Posted: Mon Oct 28, 2013 10:06 pm
by triplemzim
For those who are getting WA::
If there is no node then it is a tree.... so
for test case:
input:
output:
Re: 615 - Is It A Tree?
Posted: Wed Dec 18, 2013 7:19 pm
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.
Re: 615 - Is It A Tree?
Posted: Tue Mar 04, 2014 4:03 pm
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.
Re: 615 - Is It A Tree?
Posted: Tue Dec 02, 2014 10:38 am
by Repon kumar Roy
Got AC

Be careful about period after tree.
Series of WA for that
Again Thanks brain fry
Re: 615 - Is It A Tree?
Posted: Tue Dec 02, 2014 11:34 pm
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.
Re: 615 - Is It A Tree?
Posted: Wed Dec 24, 2014 3:15 pm
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.
Re: 615 - Is It A Tree?
Posted: Mon Jan 05, 2015 7:18 pm
by uradura
Re: 615 - Is It A Tree?
Posted: Wed Jan 07, 2015 3:01 am
by brianfry713
It looks like you figured it out.