10959  The Party, Part I
Moderator: Board moderators

 Experienced poster
 Posts: 122
 Joined: Sun Nov 13, 2005 10:25 am
 Location: Taiwan
10959  The Party, Part I
I wrote 10959 and got WA.....
Can someone give me some I/O?
thanks...
Can someone give me some I/O?
thanks...
Code: Select all
3 3
0 1
1 2
0 2
Code: Select all
1
1

 Experienced poster
 Posts: 122
 Joined: Sun Nov 13, 2005 10:25 am
 Location: Taiwan

 Experienced poster
 Posts: 122
 Joined: Sun Nov 13, 2005 10:25 am
 Location: Taiwan
#include <stdio.h>
int main()
{
return 0;
}
int main()
{
return 0;
}
Last edited by WeiMing Chen on Mon Nov 14, 2005 4:26 pm, edited 2 times in total.
First, this line: printf("%d %d %d %d %d %d\n",a[1],a[2],a[3],a[4],a[5],a[6]);
is at least strange and clearly doesn't belong into the final version of your code.
Second, the algorithm is wrong.
Consider the following input:
Here the correct output is
is at least strange and clearly doesn't belong into the final version of your code.
Second, the algorithm is wrong.
Consider the following input:
Code: Select all
1
3 2
1 2
0 1
Code: Select all
1
2

 Experienced poster
 Posts: 122
 Joined: Sun Nov 13, 2005 10:25 am
 Location: Taiwan

 Experienced poster
 Posts: 122
 Joined: Sun Nov 13, 2005 10:25 am
 Location: Taiwan
Can anyone check it for me? Thanks.
#include<iostream>
#include<math.h>
using namespace std;
int main(){
int num_of_cases, loop = 1;
cin >> num_of_cases;
while(loop <= num_of_cases){
int num_of_people;
long num_of_dance, loop_2 = 1;
cin >> num_of_people >> num_of_dance;
int danced[num_of_people][num_of_people], number[num_of_people];
//initialization
for(int n = 0; n < num_of_people; n++){
number[n] = num_of_people;
}
number[0] = 0;
while(loop_2 <= num_of_dance){
int part_1, part_2;
cin >> part_1 >> part_2;
danced[part_1][part_2] = 1;
danced[part_2][part_1] = 1;
loop_2 ++ ;
}
for(int j = 0; j < num_of_people; j++){
for(int k = 0; k < num_of_people; k++){
if(number[k] == j){
for(int m = 0; m < num_of_people; m++){
if(number[m] > j && danced[k][m] == 1){
number[m] = j+1;
}
}
}
}
}
for(int k = 1; k < num_of_people; k++){
cout << number[k] << endl;
}
loop ++ ;
}
return 0;
}
#include<iostream>
#include<math.h>
using namespace std;
int main(){
int num_of_cases, loop = 1;
cin >> num_of_cases;
while(loop <= num_of_cases){
int num_of_people;
long num_of_dance, loop_2 = 1;
cin >> num_of_people >> num_of_dance;
int danced[num_of_people][num_of_people], number[num_of_people];
//initialization
for(int n = 0; n < num_of_people; n++){
number[n] = num_of_people;
}
number[0] = 0;
while(loop_2 <= num_of_dance){
int part_1, part_2;
cin >> part_1 >> part_2;
danced[part_1][part_2] = 1;
danced[part_2][part_1] = 1;
loop_2 ++ ;
}
for(int j = 0; j < num_of_people; j++){
for(int k = 0; k < num_of_people; k++){
if(number[k] == j){
for(int m = 0; m < num_of_people; m++){
if(number[m] > j && danced[k][m] == 1){
number[m] = j+1;
}
}
}
}
}
for(int k = 1; k < num_of_people; k++){
cout << number[k] << endl;
}
loop ++ ;
}
return 0;
}
I guess it's not "bf", but "bfs" (Breadth First Search).Soarer wrote:What is bf?
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00  16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00  16:00 (UTC)
URL: http://uva.onlinejudge.org