615 - Is It A Tree?
Moderator: Board moderators
Re: 615 - Is It A Tree?
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!!
#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!!
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 615 - Is It A Tree?
"Enter root value:" should not be in the output.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 1
- Joined: Thu Dec 27, 2012 1:17 pm
615 it is a tree
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;
}
// 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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 615 it is a tree
don't use stdafx.h
doesn't match the sample I/O
doesn't match the sample I/O
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 48
- Joined: Sat Apr 06, 2013 6:02 pm
Re: 615 - Is It A Tree?
For those who are getting WA::
If there is no node then it is a tree.... so
for test case:
input:
output:
If there is no node then it is a tree.... so
for test case:
input:
Code: Select all
0 0 -1 -1
Code: Select all
Case 1 is a tree.
-
- New poster
- Posts: 5
- Joined: Sat May 26, 2012 7:25 pm
Re: 615 - Is It A Tree?
Some corner cases.
INPUT
OUTPUT
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
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?
Input:
Output:
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
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.
-
- Learning poster
- Posts: 96
- Joined: Tue Apr 23, 2013 12:54 pm
Re: 615 - Is It A Tree?
Got AC
Be careful about period after tree.
Series of WA for that
Again Thanks brain fry
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.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 615 - Is It A Tree?
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.
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!
Re: 615 - Is It A Tree?
There can be repeated edges and node can point to itself.
Problem description says
xenon wrote:I had my program rejected after rejudge too, but got AC after adjusting for bigger input (no. of nodes 10000 -> 100000).
My code accepted with number of different nodes = 15. Maximum value of node number is 50000.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.
This input is invalid.Red Scorpion wrote:input:
1 2
1
4 5
0 0
output:
Case 1 is not a tree.
Problem description says
5th case of Aarya's input is invalid.Node numbers will always be greater than zero.
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
Re: 615 - Is It A Tree?
http://ideone.com/7bNsHQ
why wrong answer????
why wrong answer????
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 615 - Is It A Tree?
It looks like you figured it out.
Check input and AC output for thousands of problems on uDebug!