There is a tool `Menu Processing / Toolbox / Topological coloring`, however only for polygons, not lines. You could still use it: 1. Create a (small) buffer around your lines. 2. Apply `Topological coloring`: it will create a new attribute `color_id` 3. Use Categorized styling and set the color to the field `color_id`