|
|
If you have WA25 and low try this test: 8 9 1 2 1 2 3 5 3 4 3 4 5 4 3 6 1 3 7 2 3 8 9 6 8 9 7 8 8 AC answer: Cost: 24 Cost: 25 What? The right answer should be Cost: 24 Cost: -1 Reply to the upper Edited by author 04.04.2011 20:38 I think answer should be 24 24, as my program does. We can replace 3->8 with 3->6 and it changes nothing. In fact,it changes; What my program shows is 24 25 What is the O(N^2) solution of this problem? I wrote simply Kraskal & DFS with assimptoty O(E * Log(E) + V * E) and got Accepted in 1.156... I want to know O(N^2) solution of this problem... My 0.093 N square solution: 1) Compute MST with Kruskal in E logE. 2) For each pair of vertices in MST compute dp[u][v] the cost of largest edge on path from u to v. This can be done by calling N depth first searches. DFS runs in O(E) and there is N - 1 edge in a MST. So this step takes (N^2) time. 3) For each edge (u, v) that isn't in a MST try to relax answer with { MST_COST - dp[u][v] + weight(u, v) }. This step is done in O(E). So, the running time of this solution is O(ElogE + E + N^2) = O(N^2). I got WA at #11. I had tested all tests on discussion and It's print right answer! Can anyone tell me some tricks? i don't know the mistake!!! What's #11??? Dude, the same to me :(( The same to me :( Can the author of the problem show the test case or someone give more tests, please? Edited by author 13.07.2018 21:54 My codes passed all testcases mentioned in the forum using stable sort or sort in c++ but still got WA on test 11. Any idea? Edited by author 18.12.2017 11:01 Edited by author 18.12.2017 11:01 i've got a wa on test 11st,could someone give me the test data? Edited by author 26.02.2011 11:03 Edited by author 26.02.2011 11:03 I've got a wa ,too. I need test data to find question. I got wa at 10th test. Who can tell me the data? Thank you ! sunzuhan@163.com 4 6 1 2 1 1 3 5 3 4 1 4 2 3 4 1 8 2 3 0 Have a try! The right answer is 2 4 At first I forgot something and failed at #11 However, my programme shows the answer 2 4, but i failed at #11. Who can tell me why? RT. I want to know what data is on test #6 Can someone give me data of test #11? I have test all data in discussion section and got right answer but my program just stuck in test #11.... 4 6 1 2 1 1 3 5 3 4 1 4 2 3 4 1 8 2 3 0 is this test #11? "highly protable"? May be "highly profitable"? And "in those aairs"? May be "in those affairs"? Edited by author 05.12.2012 10:26 use sort, wa. use stable_sort, ac Note that M (amount of edges) could be as more as N^2. Tests #12 and #15 contain perhaps M equal about 250000. Edited by author 11.03.2012 16:06 Helpful test data: 6 6 1 2 8 2 3 3 3 5 2 2 4 7 4 6 2 2 5 6 Ans: Cost: 22 Cost: 25 Edited by moderator 12.11.2023 21:26 I think O(N^2) ( Prim + DFS )is the fastest way to solve this problem , is it right ? Tell me, Why Kruscal+DFS doesn't work? I have TLE#12. Should I write Prim? I think Kruskal + DFS is enough. Maybe you need to optimize your code. Nguyen Dinh Tu ( DHSP ), my fiend , has got AC with the complexity O(N^3)( 0.89s ) . He used Prim , too. OK, then tell me, please, how to find the second answer? I use DFS... May be I should delete the largest vertic and run Kruscal again? You may try adding each non-MST edge to the MST and delete the longest MST edge in the cycle. I don't know how, but my O(n^2) solution works 0.312 sec) My O(M*M*log(N)) solution passed. New tests were added. 40 authors lost AC. My programm passes all tests from the forum and sample tests. Please, give me some tricky tests. One more question: is there test with N=1? (it's impossible according to the statement but somebody adviced to check this case. Is it nesessary?) Edited by author 12.06.2010 21:20 up up up. 1. check your sorting algo (I used bucket sort at last) 2. don't stop at the first MST-free edge, try some more edges This helped me. Please, tell me what kind of mistake can I have? I see that there are a lot of persons who has problems with Test#12. Is there smth speciale? Thanks. Edited by author 14.05.2006 15:27 I also have TLE 12 and write Kruskal and his advanced version with DSU. It doesn't meter. But when at finding secondcost i stoped finding, if secondcost became equal to firstcost i got AC at Java with 0.2 sec with complexity o(n^3) at worst case :-) Edited by author 31.07.2010 19:32 4 6 1 2 2 2 3 2 3 4 2 4 1 2 1 3 1 2 4 1 Cost: 4 Cost: 4 1: why not 1>4(cost 2, minimum. Description says if transition between A > B is possible then B > A is possible too) That gives answer: 2 2:1>3(cost 1) then 3>4(cost 2), 1+2=3 That gives answer: 3 Anyone mind explaining why its 4 and 4 in sample? "choose the minimal possible set of trans-planet passages so that he could pass from any planet to any other one via those passages" If you choose 1-3 and 3-4, you can't reach planet 2 from the other planets. Do we have to find two smallest mst that differ from each other by one edge? i got WA as well.can anyone tell me?i don't know the mistake the same :( The same :(( Please help me :( i have WA on test 12:) it's not the same:)) Maybe there is something wrong on your UFS(Union Find Set)... i need a hint, wa#11 :( bug has been founded, thanks for replying :) may be this test will hel you 4 4 1 2 2 2 3 1 2 4 3 3 4 1 answer Cost: 4 Cost: 6 but my WA11 program return Cost: 4 Cost: 5 and this test 5 6 1 2 2 1 5 1 2 3 1 2 4 1 1 3 4 4 5 3 answer Cost: 5 Cost: 6 Edited by author 21.04.2009 22:22 I've solved it only in 0.14s :( I had WA#12 when I've forgotten that the wights can be 0)) 6 6 1 2 8 2 3 3 3 5 2 2 4 7 4 6 2 2 5 6 The correct answer is: Cost: 22 Cost: 25 But the program made by me which WA 12 prints: Cost: 22 Cost: 20 I also got WA 12, but pass this test correctly... Ops, I forget that weight of an edge can be equal to 0. Edited by author 30.06.2007 20:00 |
|
|