Page 3 of 3
Posted: Tue Jul 17, 2007 6:39 pm
Hello, I don't know why I'm getting WA... My algotithm:

1 - Make a graph with no edges.
2 - Read the input of the dances and make the edges.
3 - Find the Shortest Path from the vertex 0 for all other vertices.

Is that correct? Thank you.

Posted: Wed Jul 18, 2007 12:14 am
Initilize the matrix grafo with 0 everytime u take input..

Code: Select all

``````while (casos--){
//
//
scanf("%d %d", &pessoas, &pares);
// initialize grafo here
}``````

Posted: Wed Jul 18, 2007 12:19 am
Thank you very much! I got AC!  ### 10959 - The Party, Part I

Posted: Fri Feb 27, 2009 10:53 pm

Code: Select all

``````deleted,after ACC.
``````

### Re: 10959 - The Party, Part I

Posted: Thu Jan 21, 2010 11:23 pm
Hi
Can someone help me with this task. I've tried different implementation of bfs but none worked:( here is example :

Code: Select all

``````#include <cstdio>
#include <vector>
#include <queue>

std::vector<int> a;
std::queue<int> Q;
int D;
bool color;

void Bfs(int s)
{
int u, v;
color[s] = true;
D[s] = 0;
Q.push(s);
while(!Q.empty())
{
u = Q.front();
Q.pop();
for(int i = 0; i < a[u].size(); ++i)
{
v = a[u][i];
if(!color[v])
{
color[v] = true;
D[v] = D[u]+1;
Q.push(v);
}
}
}
}

int main()
{
int t;
scanf("%d", &t);
//getchar();
//getchar();
for(int i = 0; i < t; ++i)
{
int n, m;
scanf("%d %d", &n, &m);
for(int j = 0; j < n; ++j)
{
color[j] = false;
D[j] = 0;
a[j].clear();
}
int u, v;
for(int j = 0; j < m; ++j)
{
scanf("%d %d", &u, &v);
a[u].push_back(v);
a[v].push_back(u);
}
Bfs(0);
for(int j = 1; j < n; ++j)
printf("%d\n", D[j]);
printf("\n");
}
return 0;
}

``````
WA ### Re: 10959 - The Party, Part I

Posted: Wed Mar 30, 2011 6:19 am
karo9 wrote:Hi
Can someone help me with this task. I've tried different implementation of bfs but none worked:( here is example :

Code: Select all

``````#include <cstdio>
#include <vector>
#include <queue>

std::vector<int> a;
std::queue<int> Q;
int D;
bool color;

void Bfs(int s)
{
int u, v;
color[s] = true;
D[s] = 0;
Q.push(s);
while(!Q.empty())
{
u = Q.front();
Q.pop();
for(int i = 0; i < a[u].size(); ++i)
{
v = a[u][i];
if(!color[v])
{
color[v] = true;
D[v] = D[u]+1;
Q.push(v);
}
}
}
}

int main()
{
int t;
scanf("%d", &t);
//getchar();
//getchar();
for(int i = 0; i < t; ++i)
{
int n, m;
scanf("%d %d", &n, &m);
for(int j = 0; j < n; ++j)
{
color[j] = false;
D[j] = 0;
a[j].clear();
}
int u, v;
for(int j = 0; j < m; ++j)
{
scanf("%d %d", &u, &v);
a[u].push_back(v);
a[v].push_back(u);
}
Bfs(0);
for(int j = 1; j < n; ++j)
printf("%d\n", D[j]);
printf("\n");
}
return 0;
}

``````
WA There is a extra line at the end of your output. You should only print a blank line between two cases.

### Re: 10959 - The Party, Part I

Posted: Tue Mar 12, 2013 12:36 am        i think my fault is in presentation.. I used BFS... Plz help me...    Code: Select all

``````
Got AC!!! Yaeeeeeee!!

While(1) Return Thanks! :D

``````

### Re: 10959 - The Party, Part I

Posted: Tue Mar 12, 2013 10:49 pm
The outputs of two consecutive cases will be separated by a blank line. Don't print a blank line after the last test case.