Use long type (anything 64 bit) MST Input: 9 16372 24788 000010111 001111101 010010001 010011001 111100101 010100100 110011000 100000000 111110000 Possible answer (a's should be the same, d's can differ in you answer): 163720 000000000 000000d0d 0000d000d 0000dd00d 00dd00d0d 000d00d00 0d00dd000 000000000 0dddd0000 Matrix for the graph in the answer: 000010111 001111000 010000000 010000000 110000000 010000000 100000000 100000000 100000000 Edited by author 12.05.2023 13:49 Use this site to visualise the graph using matrix and firstly change enumeration from 1,2,3... to 0,1,2... : https://graphonline.ru/# Edited by author 12.05.2023 13:55 Edited by author 12.05.2023 13:55If you have a mistake, most likely you delete connections of the input graph in a wrong way. And most likely, because you search the connected components incorrectly. write line "#define int long long" and change "int main" to "signed main" Подумайте о типе графа, дерево Can anybody give some test to judge my prog? I have WA on 5 test and cann't find my mistake. Ohhh! So stupid mistake)) Ohhh! So stupid mistake)) what? I also have WA5(( What is your algo? I use dfs and add edge between two pieces. I should use int64....... Edited by author 05.04.2009 07:22 When do you add edge between two pieces? This is a "boundary values" test. Consider a case when you have initially a full graph of ones - you have ~100^2 = 10^4 flights, and d=10^6. How much have you pay then to optimize the flights scheme? FT~~~~ I didn't know that long long is not supported. OH!!!!FT.. Realy, It's the problem ~ I didn't know that long long is not supported ,either ~ maybe the judge should update its compiler? Oh,I See.So we can only use "%I64d" to input/output?for I got WA while using "%lld" but AC with "%I64d" I know abbreviations AC, WA, TLE, DFS, BFS, DP... But what does FT stand for??? Please, give me some hint! Standard Prim's(Greedy) algo works if we assign -d to edges in graph. nothing special, just obtain a spanning tree (forest)... I think you made a confusion between verteces and parents, or something like that... try this example: 7 2 10 0000101 0000101 0001010 0010010 1100001 0011000 1100100 One of the correct answers is 16 00a000d 0000000 a0000d0 0000000 000000d 00d0000 d000d00 Thanks you. This test helped me to find the reason of WA6. Had a very silly WA6, and none of tests from this or neighbouring topics helped, so here's the one that i finally thought of and which helped: 5 1 1 01000 10001 00010 00101 01010 (1-2, 2-5, 5-4, 4-3, result is all zeros.) I've been sleepy and lazy and did a bad job with a tree building algo, which i made like this: --- (mark vertices 1..N as unconnected) for i:=1 to N do for j:=1 to N do if (i, j) is an existing edge and either i or j is yet unconnected to anything, then add (i, j) to a tree and mark both i and j as connected. --- So then it adds 1-2, then 2-5, then 3-4, and then it appears that both 4 and 5 are already connected to something, and 4-5 isn't included to a tree, which is a mistake. My programm have wa6? and on your test give: 16 0000000 000000d 000000a 00000d0 000000d 000d000 0da0d00 Is it correct? I've WA6 too. But on pervious test I've got AC. I use connected components of graph and Kruskal algo for builting spanning tree. Try to estimate the maximal possible answer to this problem. This is very easy problem. You can use: 1) BFS or DFS to find the components of the graph; 2) Prim or Kruskal algo for minimum spanning tree. spanning tree can be built during BFS. It's correct because graph is unweighted. Well, I see, that this is MST problem, but cannot get how to build a graph for it. Please, explain your step 1 more precisely. Sure, it can be solved applying BFS or DFS + Minimum Spanning Tree algorithms (Prim Algorithm). But, BFS or DFS is enough to solve it. BFS or DFS is implemented to identify Connected Component and Non-Connected Component. No need to apply MST to remove redundant edges in each Connected Component. Because, while BFS or DFS you can built identify which edges you need and don't need. Here is one part of my code to do BFS and work like Prim algo [code deleted] Edited by moderator 19.10.2019 20:33 Please give me some tests I don't use any graphs algorithms,but only DFS. If you try to solve this problem like me do: 1) break(remove) all cycles 2)Store elements of graph,witch belong to different component's of graph. 3) Connect one of them with others. (one - to every). Not every to every!!! Test 6 1000000 1000000 010000 100000 000100 001000 000001 000010 Edited by author 16.10.2009 21:29 Is this one of the solutions to the above given test? 2000000 00a0a0 000000 a00000 000000 a00000 000000 I am wondering why i got wa on test #1. I use dfs to color the edges. when one edge is not colored it means it makes a cycle and thus should be deleted. Next, every time I make dfs with a vertex, I connect it to a vertex processed before, which means the current vertex is connected to a component marked before. Lastly I used long long to store the result. But I just got wa on test #1. Can anybody please tell me sth about test #1 ? Lots of thanks Oh damn it. My first version of code is: int d, a, countd, counta; ...... long long money = d * countd + a * counta; But I didn't realize that d * countd may have already overflowed. So my AC version is: long long d, a, countd, count; ...... long long money = .....; Thus if anyone got WA at test #1 and you are sure you have the right algo, you may have failed due to the same reason as mine. My method of making graph connected works nearly by O(N^2). Are there any classic algorithmes for such problem? You should use the system of disjoint sets. I have submit my solution, where I have used the system of disjoint sets. But it has WA 1 :)) What is another way to solve this problem??? wrong answer in test 13, help me! Edited by author 15.04.2013 23:26 I had a stupid bug and found better to post it here rather than trying to look on my code. Looked, found. Edited by author 09.01.2013 18:03 Pls, anyone give me some hint about test #2 ! Thanks I have a problem with test5!.Wrong anwser!!! Can anyone help me?. What is the test 5? I have solved this problem!!!. I am stupid!. I have solved this problem!!!. I am stupid!. minimal amount of money necessary for the optimization of the existing flight scheme is long long type. Edited by author 16.11.2012 12:38The project is not very difficult. The test is so easy. ^^ Thanks for the help...i spent a day debug my code :) If you use dfs, try this test 5 1 3 01000 10111 01000 01000 01000 Answer is: 0 00000 00000 00000 00000 00000 It is rather useful. Thanks. The program should use long long or __int64 type。。。。 |
|