|
|
back to boardHHeellllpppppp...... 1329 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... 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??? 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??? eg mainc ar gava droshi arc C-ze. me aba CRASH-s madzlevs 39-e testze. sxva amoxseni rame.
AC!!!! On PASCAL I got CRASH test #39 On C++ the same solution got AC. |
|
|