## 280 - Vertex

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

Moderator: Board moderators

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

### Re: 280 - Vertex

Don't read from a file.
Check input and AC output for thousands of problems on uDebug!

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

### Re: 280 - Vertex

Post here code which you submit. In posted code above you read from file. Why do you use buffstr? You could work only with integers to avoid possible bugs because of strings. Sent you PM.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

richatibrewal
New poster
Posts: 49
Joined: Mon Jun 16, 2014 7:40 pm

### Why WA?

I am continuosly getting WA for the following code. I am using BFS and adjacency list in my algorithm. It is giving the right output for all the sample cases given in this forum.

Code: Select all

``````#include<cstdio>
#include<cstdlib>
#include<queue>
using namespace std;

{
int data;
}node;

void create(node **header,int a,int b)
{
{
return;
}

node *current;
{
if(current->data == b)
return;
}

}

void find_vertex(int v,int n)
{
bool visited[110];
int i,j=n;
queue<int> q;
node *current;

for(i=1;i<=n;i++)
visited[i]=false;

q.push(v);
//  visited[v]=true;

while(!q.empty())
{
v=q.front();
q.pop();
break;
{
i=current->data;
if(!visited[i])
{
//  printf("hii");
n--;
visited[i]=true;
q.push(i);
}
}
}

printf("%d",n);
for(i=1;i<=j;i++)
if(!visited[i])
printf(" %d",i);
printf("\n");
}

int main()
{
int n,m,a,b,v,i;

while(scanf("%d",&n)!=EOF && n)
{

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

while(scanf("%d",&a)!=EOF && a)
{
while(scanf("%d",&b)!=EOF && b)
{
}
}

/* node *current;
for(i=1;i<=n;i++)
{
{
printf("%d no edges\n",i);
continue;
}
while(current!=NULL)
{
printf("%d ",current->data);
}
printf("\n");
}*/
scanf("%d",&m);
while(m--)
{
scanf("%d",&v);
find_vertex(v,n);
}

}

return 0;
}
``````

brianfry713
Guru
Posts: 5947
Joined: Th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0
8 1 2 3 4 5 6 7 8
0
0
0
0
0
0
0
0
0
0
0
1 1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
``````
Check input and AC output for thousands of problems on uDebug!

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

### Re: 280 - Vertex

Check input and AC output for over 7,500 problems on uDebug!