Page 2 of 2

Re: 11307 - Alternative Arborescence

Posted: Thu Jun 09, 2011 10:53 pm
by Shafaet_du
7 colors gave me ac,5 color wa. But i think a tree should have no loops and chromatic number should be 2. but this problem statement says there can be loops.

Don't assume 0 as root. The node which have no in-degree is the root.

Re: 11307 - Alternative Arborescence

Posted: Wed Jun 15, 2011 3:40 pm
by Imti
I'm confused about the statement of this problem.As I can see here in this thread,everyone solved this problem with more color than 2.But Problem says..
you will be given a tree (connected graph with no simple loops)

There will be no simple loop and will be connected and we also know a tree must have n-1 edges.More than n-1 edge implies that this graph is not a tree.Like
following graph with 3 node and 3 edge is not a tree.
1 2
1 3
2 3
So,as shafaet said,this problem should be solvable with 2 color and shouldn't have any loop.May be I haven't understood problem properly.Can anyone help me
with this?

Re: 11307 - Alternative Arborescence

Posted: Wed Dec 26, 2012 11:16 am
by illusi0nist
Imti wrote:I'm confused about the statement of this problem.As I can see here in this thread,everyone solved this problem with more color than 2.But Problem says..
you will be given a tree (connected graph with no simple loops)

There will be no simple loop and will be connected and we also know a tree must have n-1 edges.More than n-1 edge implies that this graph is not a tree.Like
following graph with 3 node and 3 edge is not a tree.
1 2
1 3
2 3
So,as shafaet said,this problem should be solvable with 2 color and shouldn't have any loop.May be I haven't understood problem properly.Can anyone help me
with this?
Well, you are right about the fact that a tree is 2-colorable. But the question isn't asking you to find the minimum number of colors, rather its asking for the minimum cost. Try coming up with a small example where using 3 colors could get you a smaller cost than 2 colors. This will convince you about the question.


On the other hand I've been stuck on this question for some time, getting WA. I believe my algorithm is right (dp with 20 colors), and it works on all cases I've tried (but they were small). So what could be wrong?

Code: Select all

My bad. The dynamic structure was wrong earlier. Got AC

Re:

Posted: Mon Feb 25, 2013 8:50 am
by xueguoqing
baodog wrote:I believe number of colors can be bounded by C*log n or so.
In this case exactly 6 colors suffice.
But can you tell me why??

Re: 11307 - Alternative Arborescence

Posted: Sat May 24, 2014 9:37 am
by prashantharshi
here i used dp algorithm
still i am getting time limit exceeded
here is my code
http://ideone.com/xHJ0FI
i need help if any crucial point is there in algo

Re: 11307 - Alternative Arborescence

Posted: Tue May 27, 2014 9:37 am
by @li_kuet
I have already solved the problem.
But i'm still wondering why it is necessary to use more than two colors to color a tree :(
As we know a tree is Bi-Colorable, so wouldn't it be enough to use only two color ??
Can anyone give me an example where using three or more color is optimal than using two color... cause i couldn't come up with one :(

Re: 11307 - Alternative Arborescence

Posted: Thu Jun 12, 2014 10:28 pm
by brianfry713
prashantharshi, 6 colors is enough.
For input:

Code: Select all

11
0: 3 2 7
1:
2:
3:
4: 0 10 8 6
5:
6:
7:
8: 9
9: 1 5
10:

0
Using 2 colors the best you can do is 16, using 3 or more the best you can do is 15.
I got AC always using node 0 as the root, and couldn't find a test case where using another root got a better result.

Re: 11307 - Alternative Arborescence

Posted: Sat Jun 14, 2014 5:19 am
by @li_kuet
Thanks brianfry713 :)
Now i understand, why more than 2 colors needed :)