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 1056. Centers of the Net

Can somebody give me some hints on how to solve P1056?
Posted by abc 6 Feb 2003 11:58
Re: Can somebody give me some hints on how to solve P1056?
Posted by Marcin Mika 25 Feb 2003 02:51
1. the graph forms a tree
2. you need to give this tree direction (since the given tree is
undirected)
3. the longest path starting at node k is the maximum of 2 values:
the maximum path starting at k and going DOWN (a tree has no cycles
so you can solve this easily in linear time, i used simple DP)
and the maximum path by going UP from k.
Re: Can somebody give me some hints on how to solve P1056?
Posted by Maigo Akisame 8 Jun 2004 09:13
"the maximum path by going UP from k."

What do you mean by this?
Re: Can somebody give me some hints on how to solve P1056?
Posted by Huang SX 8 Jun 2004 11:28
How to calculate the maximum path by going up from k
Re: Can somebody give me some hints on how to solve P1056?
Posted by Stupnikov Pavel 23 Aug 2004 18:52
Just invert directions of all edges and calculate the maximum path by going DOWN form k. Realization of this thing is much easier than its description.
Re: Can somebody give me some hints on how to solve P1056?
Posted by Sid 24 Jun 2005 11:47
Just cut off leafs of tree step by step while count of nodes >2!


Edited by author 25.06.2005 14:44
Re: Can somebody give me some hints on how to solve P1056?
Posted by Mak✭kbtu 12 Feb 2010 20:09
Far not the fastest solution, but passed (0.375 sec):
1. make a bidirectional graph, connectivity of which will be kept in an array of vectors
2. start dfs from each of the verticies which are not leaves and calculate the longest path
3. Note that if there are 2 vertices, the answer is always "1 2"
The solution might run in O(N*(N+M)) time, as I guess

Edited by author 15.02.2010 13:13

Edited by author 15.02.2010 13:13