10959 - The Party, Part I
Moderator: Board moderators
-
- New poster
- Posts: 21
- Joined: Thu Jun 14, 2007 11:45 pm
-
- Learning poster
- Posts: 60
- Joined: Sun Apr 16, 2006 7:59 pm
Initilize the matrix grafo with 0 everytime u take input..
Code: Select all
while (casos--){
//
//
scanf("%d %d", &pessoas, &pares);
// initialize grafo here
}
-
- New poster
- Posts: 21
- Joined: Thu Jun 14, 2007 11:45 pm
-
- Experienced poster
- Posts: 136
- Joined: Sat Nov 29, 2008 8:01 am
- Location: narayangong,bangladesh.
- Contact:
10959 - The Party, Part I
Code: Select all
deleted,after ACC.
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
Re: 10959 - The Party, Part I
Hi
Can someone help me with this task. I've tried different implementation of bfs but none worked:( here is example :
WA 
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[1009];
std::queue<int> Q;
int D[1009];
bool color[1009];
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;
}

-
- Experienced poster
- Posts: 145
- Joined: Thu Aug 14, 2003 8:42 am
- Location: Mountain View, California
- Contact:
Re: 10959 - The Party, Part I
There is a extra line at the end of your output. You should only print a blank line between two cases.karo9 wrote:Hi
Can someone help me with this task. I've tried different implementation of bfs but none worked:( here is example :WACode: Select all
#include <cstdio> #include <vector> #include <queue> std::vector<int> a[1009]; std::queue<int> Q; int D[1009]; bool color[1009]; 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; }
Have you ever...
- Wanted to work at best companies?
- Struggled with interview problems that could be solved in 15 minutes?
- Wished you could study real-world problems?
-
- New poster
- Posts: 5
- Joined: Tue Mar 12, 2013 12:31 am
Re: 10959 - The Party, Part I








i think my fault is in presentation.. I used BFS... Plz help me...




Code: Select all
Got AC!!! Yaeeeeeee!!
While(1) Return Thanks! :D
Last edited by Top Secret on Tue Mar 12, 2013 10:49 pm, edited 2 times in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10959 - The Party, Part I
The outputs of two consecutive cases will be separated by a blank line. Don't print a blank line after the last test case.
Check input and AC output for thousands of problems on uDebug!