|
|
вернуться в форумОбщий форумPascal got TLE on 40 test, but c++ WA on test 1 whyyy /??? help!!!!!! Pascal got TLE on 40 test, but c++ WA on test 1 whyyy 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; } 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. |
|
|