1208 - Oreon

Moderator: Board moderators

draconian devil
New poster
Posts: 8
Joined: Thu Mar 28, 2013 10:46 pm

1208 - Oreon

Getting Wrong Answer on UVA 1208 Oreon. Its a straight forward MST problem i think. dont know why i got WA

Code: Select all

``````#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>

#define N 55000
using namespace std;

int P[N];

class info
{
public:
int p,c,guard;
};

bool compare(info i1, info i2)
{
if(i1.guard == i2.guard)
return i1.p < i2.p;
return i1.guard<i2.guard;
}
int Union(int node)
{
if(P[node] == node) return node;
return P[node] = Union(P[node]);
}

bool makeUnion(int p, int c)
{
if(Union(p) != Union(c))
{
P[p] = c;
return true;
}
return false;
}
int main()
{
int testcase;
cin >> testcase;
for(int  t = 1 ; t <= testcase ; t++)
{
int citynum;
vector <info> city;
cin >> citynum;

for(int i = 0 ; i < citynum ; i++)
{
for(int j = 0; j < citynum ; j++)
{
info temp;
char c;
temp.p = i; temp.c = j; cin >> temp.guard;
if(temp.guard!=0)
city.push_back(temp);

if(j < citynum-1)
cin >> c;
}
}

for(int  i = 0 ; i < citynum ; i++)
P[i] = i;

sort(city.begin(),city.end(),compare);

vector <info> result;

int a = city.size();
for(int i = 0 ; i < a ; i++)
{
if(makeUnion(city[i].p,city[i].c))
{
result.push_back(city[i]);
}
}
int b = result.size();
cout << "Case " << t << ":" << endl;

for(int i = 0 ; i < b ; i++)
{
char p,c;
p = result[i].p + 65; c = result[i].c + 65;
cout << p << "-" << c << " " << result[i].guard << endl;
}
}
}``````

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

Re: 1208 - Oreon

Change line 33 to:
P[P[p]] = P[c];
Check input and AC output for thousands of problems on uDebug!

Repon kumar Roy
Learning poster
Posts: 96
Joined: Tue Apr 23, 2013 12:54 pm

Re: 1208 - Oreon

Input :

Code: Select all

``````12
11
0, 23, 8, 2, 23, 12, 19, 17, 7, 9, 1
23, 0, 10, 24, 19, 2, 10, 10, 26, 21, 24
8, 10, 0, 8, 0, 27, 22, 3, 2, 7, 7
2, 24, 8, 0, 5, 23, 3, 9, 7, 2, 11
23, 19, 0, 5, 0, 7, 19, 18, 20, 13, 23
12, 2, 27, 23, 7, 0, 9, 26, 3, 6, 28
19, 10, 22, 3, 19, 9, 0, 25, 19, 5, 4
17, 10, 3, 9, 18, 26, 25, 0, 19, 5, 28
7, 26, 2, 7, 20, 3, 19, 19, 0, 8, 20
9, 21, 7, 2, 13, 6, 5, 5, 8, 0, 24
1, 24, 7, 11, 23, 28, 4, 28, 20, 24, 0
18
0, 0, 13, 16, 11, 18, 13, 29, 15, 12, 8, 15, 25, 15, 16, 20, 13, 15
0, 0, 22, 9, 13, 13, 15, 15, 14, 26, 17, 15, 18, 22, 2, 18, 27, 14
13, 22, 0, 14, 27, 28, 4, 4, 21, 16, 8, 8, 23, 21, 28, 4, 25, 22
16, 9, 14, 0, 18, 1, 23, 9, 18, 27, 7, 22, 10, 11, 15, 0, 7, 11
11, 13, 27, 18, 0, 25, 6, 1, 18, 8, 27, 19, 16, 20, 9, 14, 2, 9
18, 13, 28, 1, 25, 0, 5, 17, 23, 24, 24, 8, 12, 21, 24, 16, 9, 12
13, 15, 4, 23, 6, 5, 0, 5, 5, 21, 24, 2, 22, 8, 23, 4, 17, 24
29, 15, 4, 9, 1, 17, 5, 0, 22, 27, 29, 0, 25, 27, 19, 26, 15, 25
15, 14, 21, 18, 18, 23, 5, 22, 0, 11, 11, 7, 22, 16, 20, 24, 16, 8
12, 26, 16, 27, 8, 24, 21, 27, 11, 0, 5, 24, 22, 20, 25, 13, 25, 26
8, 17, 8, 7, 27, 24, 24, 29, 11, 5, 0, 28, 7, 20, 6, 18, 13, 12
15, 15, 8, 22, 19, 8, 2, 0, 7, 24, 28, 0, 21, 19, 3, 4, 10, 15
25, 18, 23, 10, 16, 12, 22, 25, 22, 22, 7, 21, 0, 5, 26, 10, 14, 1
15, 22, 21, 11, 20, 21, 8, 27, 16, 20, 20, 19, 5, 0, 23, 20, 8, 23
16, 2, 28, 15, 9, 24, 23, 19, 20, 25, 6, 3, 26, 23, 0, 9, 25, 29
20, 18, 4, 0, 14, 16, 4, 26, 24, 13, 18, 4, 10, 20, 9, 0, 15, 7
13, 27, 25, 7, 2, 9, 17, 15, 16, 25, 13, 10, 14, 8, 25, 15, 0, 3
15, 14, 22, 11, 9, 12, 24, 25, 8, 26, 12, 15, 1, 23, 29, 7, 3, 0
9
0, 5, 20, 21, 1, 5, 21, 4, 20
5, 0, 2, 18, 15, 6, 6, 5, 25
20, 2, 0, 7, 25, 27, 1, 9, 15
21, 18, 7, 0, 8, 19, 22, 7, 6
1, 15, 25, 8, 0, 4, 20, 15, 3
5, 6, 27, 19, 4, 0, 14, 13, 22
21, 6, 1, 22, 20, 14, 0, 29, 26
4, 5, 9, 7, 15, 13, 29, 0, 28
20, 25, 15, 6, 3, 22, 26, 28, 0
11
0, 21, 24, 18, 9, 4, 19, 27, 24, 11, 17
21, 0, 8, 17, 3, 29, 13, 15, 20, 28, 27
24, 8, 0, 21, 11, 25, 4, 20, 0, 15, 23
18, 17, 21, 0, 21, 29, 10, 26, 16, 8, 2
9, 3, 11, 21, 0, 0, 27, 14, 2, 29, 15
4, 29, 25, 29, 0, 0, 15, 27, 4, 9, 6
19, 13, 4, 10, 27, 15, 0, 18, 27, 19, 23
27, 15, 20, 26, 14, 27, 18, 0, 14, 3, 4
24, 20, 0, 16, 2, 4, 27, 14, 0, 13, 10
11, 28, 15, 8, 29, 9, 19, 3, 13, 0, 26
17, 27, 23, 2, 15, 6, 23, 4, 10, 26, 0
2
0, 24
24, 0
12
0, 15, 16, 15, 26, 1, 23, 21, 0, 6, 23, 7
15, 0, 8, 3, 8, 8, 11, 8, 4, 7, 20, 13
16, 8, 0, 17, 6, 24, 10, 9, 20, 8, 24, 19
15, 3, 17, 0, 17, 9, 22, 3, 25, 0, 28, 27
26, 8, 6, 17, 0, 27, 13, 27, 27, 16, 27, 27
1, 8, 24, 9, 27, 0, 17, 4, 20, 25, 15, 29
23, 11, 10, 22, 13, 17, 0, 18, 10, 27, 9, 15
21, 8, 9, 3, 27, 4, 18, 0, 15, 23, 25, 3
0, 4, 20, 25, 27, 20, 10, 15, 0, 14, 23, 3
6, 7, 8, 0, 16, 25, 27, 23, 14, 0, 12, 3
23, 20, 24, 28, 27, 15, 9, 25, 23, 12, 0, 18
7, 13, 19, 27, 27, 29, 15, 3, 3, 3, 18, 0
7
0, 8, 19, 20, 3, 0, 10
8, 0, 6, 14, 13, 21, 3
19, 6, 0, 12, 27, 10, 8
20, 14, 12, 0, 10, 13, 23
3, 13, 27, 10, 0, 20, 26
0, 21, 10, 13, 20, 0, 10
10, 3, 8, 23, 26, 10, 0
16
0, 20, 19, 4, 29, 13, 1, 1, 24, 5, 3, 6, 20, 15, 26, 26
20, 0, 2, 19, 11, 10, 9, 26, 20, 0, 28, 20, 20, 4, 4, 11
19, 2, 0, 22, 0, 0, 8, 24, 8, 28, 17, 23, 29, 5, 20, 1
4, 19, 22, 0, 19, 13, 6, 24, 21, 14, 28, 3, 27, 23, 18, 28
29, 11, 0, 19, 0, 20, 29, 8, 20, 29, 0, 5, 11, 20, 22, 21
13, 10, 0, 13, 20, 0, 0, 6, 23, 3, 24, 20, 27, 1, 0, 11
1, 9, 8, 6, 29, 0, 0, 21, 21, 20, 15, 2, 14, 29, 6, 15
1, 26, 24, 24, 8, 6, 21, 0, 21, 5, 7, 23, 5, 4, 10, 0
24, 20, 8, 21, 20, 23, 21, 21, 0, 2, 1, 2, 11, 25, 17, 10
5, 0, 28, 14, 29, 3, 20, 5, 2, 0, 0, 17, 27, 19, 12, 8
3, 28, 17, 28, 0, 24, 15, 7, 1, 0, 0, 21, 8, 13, 19, 3
6, 20, 23, 3, 5, 20, 2, 23, 2, 17, 21, 0, 2, 29, 8, 17
20, 20, 29, 27, 11, 27, 14, 5, 11, 27, 8, 2, 0, 16, 21, 10
15, 4, 5, 23, 20, 1, 29, 4, 25, 19, 13, 29, 16, 0, 21, 1
26, 4, 20, 18, 22, 0, 6, 10, 17, 12, 19, 8, 21, 21, 0, 23
26, 11, 1, 28, 21, 11, 15, 0, 10, 8, 3, 17, 10, 1, 23, 0
16
0, 13, 7, 5, 26, 11, 18, 5, 27, 16, 21, 15, 3, 2, 5, 29
13, 0, 7, 11, 26, 7, 16, 3, 6, 6, 14, 18, 8, 20, 29, 16
7, 7, 0, 22, 25, 1, 21, 1, 8, 16, 28, 28, 15, 27, 28, 17
5, 11, 22, 0, 24, 13, 5, 0, 5, 27, 28, 29, 1, 17, 23, 28
26, 26, 25, 24, 0, 24, 10, 21, 4, 20, 4, 24, 12, 19, 0, 19
11, 7, 1, 13, 24, 0, 16, 19, 17, 4, 25, 17, 24, 27, 9, 27
18, 16, 21, 5, 10, 16, 0, 5, 9, 21, 17, 0, 16, 15, 20, 15
5, 3, 1, 0, 21, 19, 5, 0, 26, 0, 9, 4, 7, 3, 7, 15
27, 6, 8, 5, 4, 17, 9, 26, 0, 8, 8, 10, 15, 19, 26, 2
16, 6, 16, 27, 20, 4, 21, 0, 8, 0, 4, 26, 25, 9, 8, 14
21, 14, 28, 28, 4, 25, 17, 9, 8, 4, 0, 15, 0, 4, 23, 9
15, 18, 28, 29, 24, 17, 0, 4, 10, 26, 15, 0, 15, 19, 8, 14
3, 8, 15, 1, 12, 24, 16, 7, 15, 25, 0, 15, 0, 21, 26, 24
2, 20, 27, 17, 19, 27, 15, 3, 19, 9, 4, 19, 21, 0, 1, 27
5, 29, 28, 23, 0, 9, 20, 7, 26, 8, 23, 8, 26, 1, 0, 19
29, 16, 17, 28, 19, 27, 15, 15, 2, 14, 9, 14, 24, 27, 19, 0
17
0, 5, 6, 25, 3, 14, 17, 20, 7, 6, 2, 12, 29, 3, 11, 1, 5
5, 0, 21, 29, 28, 3, 14, 13, 10, 8, 16, 13, 14, 29, 17, 0, 2
6, 21, 0, 11, 28, 29, 25, 2, 29, 22, 21, 17, 19, 25, 3, 22, 22
25, 29, 11, 0, 29, 25, 11, 12, 25, 29, 7, 2, 16, 3, 28, 4, 12
3, 28, 28, 29, 0, 11, 4, 1, 7, 9, 26, 4, 5, 11, 27, 20, 14
14, 3, 29, 25, 11, 0, 6, 4, 12, 8, 25, 1, 1, 1, 0, 4, 19
17, 14, 25, 11, 4, 6, 0, 17, 19, 23, 10, 8, 3, 22, 23, 3, 27
20, 13, 2, 12, 1, 4, 17, 0, 27, 17, 24, 2, 12, 26, 6, 21, 27
7, 10, 29, 25, 7, 12, 19, 27, 0, 21, 25, 16, 16, 19, 29, 7, 2
6, 8, 22, 29, 9, 8, 23, 17, 21, 0, 1, 10, 9, 1, 21, 9, 20
2, 16, 21, 7, 26, 25, 10, 24, 25, 1, 0, 23, 20, 29, 14, 14, 19
12, 13, 17, 2, 4, 1, 8, 2, 16, 10, 23, 0, 10, 20, 11, 17, 0
29, 14, 19, 16, 5, 1, 3, 12, 16, 9, 20, 10, 0, 16, 4, 10, 27
3, 29, 25, 3, 11, 1, 22, 26, 19, 1, 29, 20, 16, 0, 6, 11, 11
11, 17, 3, 28, 27, 0, 23, 6, 29, 21, 14, 11, 4, 6, 0, 1, 26
1, 0, 22, 4, 20, 4, 3, 21, 7, 9, 14, 17, 10, 11, 1, 0, 0
5, 2, 22, 12, 14, 19, 27, 27, 2, 20, 19, 0, 27, 11, 26, 0, 0
21
0, 2, 19, 10, 4, 11, 15, 13, 8, 0, 16, 21, 21, 18, 24, 20, 9, 13, 4, 11, 19
2, 0, 26, 22, 4, 5, 11, 7, 0, 5, 4, 4, 20, 13, 0, 15, 28, 29, 9, 2, 27
19, 26, 0, 18, 18, 21, 27, 29, 9, 15, 20, 28, 24, 5, 10, 3, 20, 0, 6, 18, 4
10, 22, 18, 0, 0, 21, 20, 26, 22, 14, 10, 21, 19, 0, 18, 15, 7, 13, 24, 3, 29
4, 4, 18, 0, 0, 11, 18, 3, 4, 14, 0, 8, 20, 20, 7, 5, 25, 8, 12, 9, 4
11, 5, 21, 21, 11, 0, 15, 21, 3, 3, 18, 5, 10, 6, 3, 4, 8, 3, 28, 29, 21
15, 11, 27, 20, 18, 15, 0, 5, 13, 18, 21, 13, 10, 27, 28, 15, 14, 21, 14, 29, 29
13, 7, 29, 26, 3, 21, 5, 0, 9, 2, 27, 21, 13, 0, 24, 1, 12, 20, 4, 26, 16
8, 0, 9, 22, 4, 3, 13, 9, 0, 22, 16, 19, 12, 7, 25, 1, 25, 0, 19, 11, 17
0, 5, 15, 14, 14, 3, 18, 2, 22, 0, 17, 3, 18, 13, 2, 26, 20, 8, 28, 7, 10
16, 4, 20, 10, 0, 18, 21, 27, 16, 17, 0, 9, 22, 3, 29, 11, 17, 0, 11, 23, 29
21, 4, 28, 21, 8, 5, 13, 21, 19, 3, 9, 0, 4, 12, 10, 9, 0, 24, 10, 29, 7
21, 20, 24, 19, 20, 10, 10, 13, 12, 18, 22, 4, 0, 11, 19, 13, 17, 27, 23, 28, 13
18, 13, 5, 0, 20, 6, 27, 0, 7, 13, 3, 12, 11, 0, 28, 14, 26, 6, 17, 4, 11
24, 0, 10, 18, 7, 3, 28, 24, 25, 2, 29, 10, 19, 28, 0, 27, 28, 11, 24, 0, 5
20, 15, 3, 15, 5, 4, 15, 1, 1, 26, 11, 9, 13, 14, 27, 0, 22, 26, 23, 6, 16
9, 28, 20, 7, 25, 8, 14, 12, 25, 20, 17, 0, 17, 26, 28, 22, 0, 1, 14, 13, 4
13, 29, 0, 13, 8, 3, 21, 20, 0, 8, 0, 24, 27, 6, 11, 26, 1, 0, 28, 4, 15
4, 9, 6, 24, 12, 28, 14, 4, 19, 28, 11, 10, 23, 17, 24, 23, 14, 28, 0, 26, 1
11, 2, 18, 3, 9, 29, 29, 26, 11, 7, 23, 29, 28, 4, 0, 6, 13, 4, 26, 0, 2
19, 27, 4, 29, 4, 21, 29, 16, 17, 10, 29, 7, 13, 11, 5, 16, 4, 15, 1, 2, 0
10
0, 28, 20, 27, 20, 22, 3, 22, 2, 18
28, 0, 27, 19, 1, 1, 18, 24, 12, 11
20, 27, 0, 6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