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 1553. Caves and Tunnels

Why WA?...
Posted by Victor Barinov (TNU) 22 Sep 2007 20:28
My algo is O(n * sqrt(n)) But i have WA on test 18. My solution gives same answers with brute force solution on my random tests. But what is 18-th test? Can anybody help me?
Re: Why WA?...
Posted by Vedernikoff Sergey 22 Sep 2007 20:34
Maybe, arithmetic overflow? Some answers may not fit in the standard 32-bit integer types...
Re: Why WA?...
Posted by Victor Barinov (TNU) 22 Sep 2007 23:57
Really?
Yes, I use usual int instead __int64. But in problem statement Q <= 10^5 and V <= 10^4 for all I queryes. So all values on nodes is <= 10^5*10^4. It is less than 2^31-1. But... maybe I misuderstud anything?
BTW I will try submit with __int64 :)
Thank You!

Any more ideas?
Re: Why WA?...
Posted by Paul Diac 23 Sep 2007 00:05
It fits in 32 bit integers. (I got AC using long). I also used O(n * sqrt(n)) (teoretically) but I can't think why you get WA on test 18... there must be a mistake someware.
Re: Why WA?...
Posted by Victor Barinov (TNU) 23 Sep 2007 02:26
AC now!

here it is program that generated contrary test for my solution:

n = 10000;
printf( "%d\n", n );
  for  (i = 0;  i < n-1;  ++i)
  {
      printf( "%d %d\n", random(i+1)+1, i+2 );
  }
m = 1000;
printf( "\n%d\n", m );
k = random(m);
    for ( i = 0 ; i < k ; i++ )
        printf( "I %d %d\n", random(n) + 1, random(10001) );

    for ( i++ ; i < m ; i++ )
        printf( "G %d %d\n", random(n) + 1, random(n) + 1 );
Re: Why WA?...
Posted by Khúc Anh Tuấn 27 Sep 2007 00:41
How can solve this problem in O(N * sqrt(N)) ?? Is it simple to implement ?

My solution is O(N * log^2(N)). But it's very complex and slow ( 4.25s )
Re: Why WA?...
Posted by Alias (Alexander Prudaev) 2 Oct 2007 09:29
my program work about N*sqrt(N) but i have TL 17
any ideas about this test?
Why TL?????????
Posted by Oybek 15 Dec 2007 17:16
Can U tell me about ur method

this is my email oybek_all@yahoo.com
Re: Why TL?????????
Posted by Denis Koshman 14 Jul 2008 21:42


Edited by author 03.08.2008 14:40
No subject
Posted by KantSU: Vashegin Roman 3 Sep 2008 00:06
help me, please!!  How solved? What algorithm? Tried through LCA and RSQ but could not....mail: Vashegin_roman@mail.ru
Re: No subject
Posted by Denis Koshman 9 Sep 2008 02:43
Build clusters of O(sqrt(N)) in size using DFS-inside-DFS. Outer clusters tree will have O(sqrt(N)) diameter. Optimize by skipping a cluster completely when you find a way. When you increase radiation level, enumerate all "downward portals" to other clusters passing through incremented node, and update their skip-values (maximal radiation level on the path from downward portal towards upward portal to parent cluster). Keep separate list of in-cluster edges. Although outer cluster tree's diameter is O(sqrt(N)), its size is still O(N) (there can be a lot of tiny leaf clusters). You don't want to enumerate all of them if you want to stay at O(sqrt(N)) during increments :)

Edited by author 09.09.2008 02:44
Re: No subject
Posted by svr 23 Jan 2009 15:17
More simply:
Divide Tree in sqrt(N) layers and in clusters.
If cluster small jumping through layer when forming
answer on 'G' query, but renewing for verteces of this cluster information on each 'I' query.
If cluster big go through it by step by step but in this case renewing information only for one vertex in 'I' query.
Re: Why WA?...
Posted by cxjyxx_me 28 Apr 2012 07:02
why we have to use __int64?