How to set the first node green color and the last node red color

As shown in the picture,I may have many paths,every path may have different length

But I need to draw the frist node in the green color and the last node in the red color

How to do that?

my dot file: (86 Bytes)

I suggest looking at, at least page 5 (fancy graph).
Also style | Graphviz

One solution:

strict digraph{
  4 [style=filled color=red]
  f [style=filled color=red]
    node [style=filled color=green]
    1 a
  "1" -> "2" ->"3" ->"4";
   "a" -> "b" -> "c" -> "d" -> "e" -> "f" 


Or are you asking how to identify nodes with no incoming edges (green) or no outgoing edges (red)??

thank you for your answer!

I don’t need to identify nodes.But I need paint to all the no incoming nodes to green color and all the no outgoing nodes to red color.

your code seems that I need to specify the no incoming node is “1”(“a”) and the no outgoing node is “4”(“f”),but I fact the dot file is generated automaticly, I don’t know what is the no incoming node and what is the no incoming node

Here is a (Linux) shell script that takes your automatically-generated file & modifies it to meet your needs:

F=`basename $f .gv`  # assumes .gv, change for .dot
gvpr -c '
}' $f  |
dot -T$T >$F.$T

GVPR is part of the Graphviz package. It is documented here:

  • indegree is the count of inbound edges
  • outdegree is the count of outbound edges


strict digraph {
        1       [color=green,
        1 -> 2;
        2 -> 3;
        4       [color=red,
        3 -> 4;
        a       [color=green,
        a -> b;
        b -> c;
        c -> d;
        d -> e;
        f       [color=red,
        e -> f;

Thank you very much!

I will have a test