Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (graph.Directed == true) throw new ArgumentException();
- colors = new int[graph.VerticesCount];
- int maxColor = 0;
- colors[0] = maxColor; //najwyzszy kolor
- for (int i = 1; i < graph.VerticesCount; i++)
- {
- colors[i] = int.MaxValue;
- }
- for (int v = 0; v < graph.VerticesCount; v++)
- {
- if (graph.InDegree(v) == 0)
- {
- colors[v] = 0;
- continue;
- }
- for (int k=0;k<=maxColor;k++)
- {
- bool isColorUsed = false;
- foreach(Edge e in graph.OutEdges(v))
- {
- if (colors[e.To] == k)
- {
- isColorUsed = true;
- break;
- }
- }
- if (!isColorUsed)
- {
- colors[v] = k;
- break;
- }
- }
- if (colors[v]==int.MaxValue)
- {
- maxColor++;
- colors[v] = maxColor;
- }
- }
- return maxColor + 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement