Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения |
Overrated | FaNato4kA_TiMoFeYa | 1329. Галактическая история | 27 апр 2024 01:12 | 1 |
Overrated FaNato4kA_TiMoFeYa 27 апр 2024 01:12 |
Why WA6? | GastonFontenla | 1329. Галактическая история | 9 сен 2015 20:19 | 2 |
Why WA6? GastonFontenla 24 авг 2015 08:42 My algorithm: I run BFS to assign levels (DISTANCE TO THE ROOT) to each node. Then, when read the queries: If the level of both nodes are the same, no exist any path between them. Answer is 0 If the level of qA is less than level of qB, maybe exist a path between them. Find it. If found a path, Answer is 1 If no path had been found, and the level of qA is greater than level of qB, Find a path. If found a path, Answer is 2 If none of the previous worked, the answer to the querie is 0. I read that it could be solved with LCA, but I think that it's better and elegant algo. Please help me. Maybe my algo is right, but my problem may be on the code. If need to see code, i'll post it. Okey, I solved it :D got AC, but the solution was rejudged. Now is TLE |
what's in test 12? | Giorgi Pataraia [Tbilisi SU] | 1329. Галактическая история | 26 мар 2012 00:10 | 1 |
solved :x Edited by author 26.03.2012 03:51 |
If you have CRASH... | Burmistrov Ivan (USU) | 1329. Галактическая история | 2 сен 2010 15:35 | 2 |
If you have CRASH, may be, will help for you to make columns of a global variable and to clean from definitions of procedures. I got AC... Maybe you should increase the stack size as well. |
Tips | MAK | 1329. Галактическая история | 2 сен 2010 15:33 | 1 |
Tips MAK 2 сен 2010 15:33 If you get WA2 try this one: Input: 3 3 2 2 1 1 -1 3 1 2 3 2 1 3 Output: 1 2 1 Also if you get WA12 pay attention for: "All identifiers lie between 0 and 40000." |
TLE#47 | dimozzz | 1329. Галактическая история | 5 апр 2009 13:23 | 7 |
TLE#47 dimozzz 11 мар 2007 15:14 I try to solve it for O(n * log(n) * log(n)). I don't understand why I can't passed it? Please help me. I can send my code. Edited by author 11.03.2007 15:15 Re: TLE#47 Giorgi Saghinadze (Tbilisi SU) 11 мар 2007 16:10 you can solve this problem using one DFS. think about it Thank you very much. It's problem very easy... And I'm very stupid. Now I have AC. I've solved it with LCA Does more simple way exists? Re: TLE#47 Giorgi Saghinadze (Tbilisi SU) 11 мар 2007 21:40 I've solved it with LCA Does more simple way exists? Yes of course. run DFS once and for each vertex remember when you came to this vertex and when you returned there. and then it's very easy to find answer:) Thank you for really good idea It's much more simple to implement then LCA:) |
I want to know if there's other ways to solve the problem besides LCA | Fat Peter | 1329. Галактическая история | 17 янв 2007 14:47 | 9 |
Mine algo does not use LCA, however it has time complexity O(V) for preprocessing and O(1) for querys. It is a lot easier than LCA... If you want to know more, you can drop me a mail to: oberon [at] verba [d0t] com [d0t] ua Replace [at] by @, and [d0t] by .; Firstly I have sent it and it returned =( Secondly I have sent it again and it was returned once again =(( The third time I have sent it from different addresse and It have not returned yet. I hope it will reach you soon... If you won't recieve that email, drop a few words here (to the web-board) and we will think about different ways of communication =)... Unfortunately,I must say that I didn't receive your E-mail :'( Did you have msn? I have tried once more... I think moderators will forgive me for posting idea here: ----------------- idea was here =) ----------------- BTW. I do not have MSN... Let me know when you will read this, so I could clean up the forum... Edited by author 25.02.2005 18:21 I've read it..I think it's a wonderful idea..You can clean it...Thank yor for your help. Edited by author 25.02.2005 14:52 Could u tell me the method? I also want to know. Pls send to ahyangyi@gmail.com or ahyangyi2@hotmail.com, thank you IMHO, the simplest way to solve it - skip lists. Simplest 2-level skip-lists gives time complexity for any query O(logN) and O(NlogN) for precalc. AC ~ 0.45 secs. |
WA 14 | Alexander Prudaev | 1329. Галактическая история | 2 окт 2006 21:50 | 1 |
WA 14 Alexander Prudaev 2 окт 2006 21:50 please help, give me some exemples if descendant(A,B)==true, if A is descendant for B int level(int X) == level of vertex with number X, level(root)==0 my code: ... for (i=0;i<L;i++) { int a,b; scanf("%i %i",&a,&b); if (a==b){printf("0\n");continue;} if (level(a)<level(b)) { if (descendant(b,a)) printf("1\n"); else printf("0\n"); } else { if (descendant(a,b)) printf("2\n"); else printf("0\n"); } } WHY I got WA14? please help me |
STL teching (+) | Ilya Rasenstein (Lyceum #40) | 1329. Галактическая история | 1 июн 2006 09:08 | 3 |
IMHO, it's one of the best problemsm that helps you teaching STL. Than why 0.828 sec? Try do it better :) The problem number 1000 also gives an opportunity to use STL :D cout << accumulate( istream_iterator<int>(cin), istream_iterator<int>(), 0 ); |
Help, please! | malchreal | 1329. Галактическая история | 3 мар 2006 13:40 | 1 |
After having 'Stack Overflow', now i have WA 42 and I don't know, why! Could you give me some tests or hints,please! |
Getting TLE40 | Alex_SyktSU | 1329. Галактическая история | 3 фев 2006 21:03 | 1 |
If somebody know how to make my variant working faster(if it's possible), please write to nonename@narod.ru. I think in the worst case it needs O(n*l), but I also think it's quite clear to understand. May be using memory will be faster, but haven't tried. Other variant is that algorithm is wrong. int i,j,n,l; int work[40005]; cin >> n; work[0]=-1; for (i=0;i<n;i++){ int tmp; cin >> tmp; cin >> work[tmp+1]; } cin >> l; int a,b,fl=0; for (i=0;i<l;i++){ fl=0; cin >> a >> b; int wka=a; int wkb=b; while (wka+wkb+2){ wka=work[wka+1]; wkb=work[wkb+1]; if (wka==b){ fl=2; break; } if (wkb==a){ fl=1; break; } } cout << fl << endl; } |
HHeellllpppppp...... 1329 | Counter Terrorist TSU | 1329. Галактическая история | 16 дек 2005 15:41 | 6 |
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... Can Any body help...???!!! First test has not to be the sample... you need only correct O(n) algo 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. eg mainc ar gava droshi arc C-ze. me aba CRASH-s madzlevs 39-e testze. sxva amoxseni rame.
AC!!!! Nika Jimsheleishvili (Tbilisi SU) 16 дек 2005 15:41 On PASCAL I got CRASH test #39 On C++ the same solution got AC. |
Help! What wrong with my source in C. Idental program in pascal got TLE(20), but C program got WA(1). | Aleksey Meshnikovsky | 1329. Галактическая история | 7 дек 2005 13:50 | 3 |
C++ Program: #include <stdio.h> int main() { long st[40005], n, l, a, b, i, j;
for (i = 0; i < 40005; ++i) st[i] = -2;
scanf("%ld", &n); for (i = 0; i < n; ++i) { scanf("%ld%ld", &a, &b); st[a] = b; }
scanf("%ld", &l); for (j = 0; j < l; ++j) {
scanf("%ld%ld", &a, &b);
if (j > 0) printf("\n"); i = a; while (i >= 0) { i = st[i]; if (i == b) break; } if (i == b) {printf("2"); continue;} i = b; while (i >= 0) { i = st[i]; if (i == a) break; } if (i == a) {printf("1"); continue;}
printf("0"); }
return 0; } 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. #include <fstream> #include <iostream> using namespace std; int main(void) { long int st[40000], n, l, a, b, i, j;
cin >> n; for (i=0; i<n; 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; } #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; } |
To administrator: please remake text of problem | [NU GYM] I am get tester... | 1329. Галактическая история | 10 ноя 2005 11:16 | 2 |
"Файл input.txt содержит ..." Fixed Vladimir Yakovlev (USU) 10 ноя 2005 11:16 |
How to solve it without dynamic structures? | Samsonov Alex [SESC USU] | 1329. Галактическая история | 10 ноя 2005 10:29 | 7 |
As I understand, we should remember all the sons of a current node. To do it we should use either [40000][40000] or dynamic structures... We can't make DFS fast if we remember only fathers, am I right? You are right. But we can store for each element his father, left son and right brother (3*40000) and DFS will be fast. Good luck! And what for should we store fathers? BTW, is 40000 functions enough for stack to get CRASH(STACK_OVERFLOW) on Test 4? Edited by author 07.06.2005 20:43 I think that your DFS is bad. 40000 functions here must be OK. (And Test 4 should not be very large). Yes. It turned out that I forgot to clear the zero element of the array. But now I've got WA12 :( You are wrong. If we remember parent for all vertex, we will can make DFS(in any kind) for O(n). So, my program work more slow, but use only 794 kb. |
What about stack size? (+) | Kit (Vologda SPU) | 1329. Галактическая история | 30 авг 2005 14:09 | 2 |
Adding this simple fragment procedure search2(d: longint); begin if d <= 50000 then search2(d + 1); end; ............ search2(0); I turn Stack Overflow 29 into SO1. Is it mean, that I must avoid recursion in this task? How much stack size? Edited by author 30.08.2005 14:10 |
TLE test1??? | Гладких Максим | 1329. Галактическая история | 15 авг 2005 23:13 | 1 |
Why the hell this c program gets TLE on test 1? It works perfectly on sample. #include <stdio.h> int main() { int ar[40000],n,i,a,b,l,ta,tb; char o[40000]; //freopen("in","r",stdin); scanf("%d",&n); for(i=0;i<n;i++) ar[i]=0; for(i=0;i<n;i++) { scanf("%d%d",&a,&b); a--; ar[a]=b; } scanf("%d",&l); for(i=0;i<l;i++) { scanf("%d%d",&a,&b); a--; b--; ta=a; tb=b; while(ta!=-1&&ta!=b&&ta!=0) ta=ar[ta]-1; if(ta==b) { o[i]=2; //printf("2\n"); continue; } while(tb!=-1&&tb!=a&&ta!=0) tb=ar[tb]-1; if(tb==a) { o[i]=1; //printf("1\n"); continue; } o[i]=0; //printf("0\n"); } for(i=0;i<l;i++) printf("\n%d",o[i]); return 0; } |
To administrator: Test 42 bad!!! | Bandera | 1329. Галактическая история | 17 окт 2004 12:29 | 4 |
In this problem in input data must be TREE, because in input write:" The input file contains full history TREE description...". But it is not a tree, because there are cycle... Yes, I think that it is true. I used LCA-offline algorithm (I know that it is a bit complicated, but..) and got WA on 42 test many times. At the end of the contest I've made the same decision as yours. it's impossible to describe cycle by such way of input, IMHO The problem was redjudged, some authors got AC now Sorry, for this mistake |
Memory Limit | Nazarov Denis (nsc2001@rambler.ru) | 1329. Галактическая история | 16 окт 2004 14:00 | 2 |
Memory Limit Nazarov Denis (nsc2001@rambler.ru) 16 окт 2004 13:27 Hey! I've lost about 30 minutes to run my program under 3MB. I am sure that my program don't use more than 3MB. Your online judge have some troubles with determinating Memory Usage of PASCAL programs. Please fix it. (I mean set Memory Limit = 5MB) Don't use dynamic structures! It use too much memory. |