ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1329. Galactic History

HHeellllpppppp...... 1329
Posted by Counter Terrorist TSU 8 Dec 2005 16:26
Wrong Answer On Test 1

help...

#include <fstream>
#include <iostream>
using namespace std;

int main(void) {
    long int st[40001], n, l, a, b, i, j;

    cin >> n;

    for (i=0; i<40001; i++)
        st[i] = -2;

    for (i=0; i<n; i++) {
        cin >> a >> b;
        st[a] = b;
    }

    cin >> l;

    for (j=0; j<l; j++) {
        cin >> a >> b;

        i = a;
        while (i >= 0 && i != b)
            i = st[i];

        if (i == b) {
            cout << "2\n";
            continue;
        }

        i = b;
        while (i >= 0 && i != a)
            i = st[i];

        if (i == a) {
            cout << "1\n";
            continue;
        }

        cout << "0\n";
    }
    return 0;
}
Every Body has some problem in c++ in this problem...
Posted by Counter Terrorist TSU 8 Dec 2005 16:28
Every Body has some problem in c++ in this problem...

Can Any body help...???!!!
Re: Every Body has some problem in c++ in this problem...
Posted by Sid 8 Dec 2005 17:10
First test has not to be the sample... you need only correct O(n) algo
Can Any body Answer On my question???
Posted by Counter Terrorist TSU 9 Dec 2005 11:47
I know this algorithm is not so good, but I am disapointed because Pascal Program with this algo got TLE on 40 test, but C++ program got WA on test 1. why ?


Pascal Programm:
var l, i, j, n, a, b: longint;
st: array[0..40000] of longint;

begin

for i := 0 to 40000 do
st[i] := -2;

readln(n);
for i := 1 to n do begin
readln(a, b);
st[a] := b;
end;

readln(l);
for j := 1 to l do begin
readln(a, b);

i := a;
while i >= 0 do begin
i := st[i];
if (i = b) then break;
end;
if i = b then begin writeln(2); continue; end;

i := b;
while i >= 0 do begin
i := st[i];
if (i = a) then break;
end;
if i = a then begin writeln(1); continue; end;

writeln(0);
end;

end.
Re: Can Any body Answer On my question???
Posted by Nika Jimsheleishvili (Tbilisi SU) 13 Dec 2005 15:57
 eg mainc ar gava droshi arc C-ze.
 me aba CRASH-s madzlevs 39-e testze.
 sxva amoxseni rame.
AC!!!!
Posted by Nika Jimsheleishvili (Tbilisi SU) 16 Dec 2005 15:41
 On PASCAL I got CRASH test #39
 On C++ the same solution got AC.