Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. if (graph.Directed == true) throw new ArgumentException();
  2.  
  3.             colors = new int[graph.VerticesCount];
  4.             int maxColor = 0;
  5.             colors[0] = maxColor; //najwyzszy kolor
  6.             for (int i = 1; i < graph.VerticesCount; i++)
  7.             {
  8.                 colors[i] = int.MaxValue;
  9.             }
  10.             for (int v = 0; v < graph.VerticesCount; v++)
  11.             {
  12.                 if (graph.InDegree(v) == 0)
  13.                 {
  14.                     colors[v] = 0;
  15.                     continue;
  16.                 }
  17.  
  18.                 for (int k=0;k<=maxColor;k++)
  19.                 {
  20.                     bool isColorUsed = false;
  21.                     foreach(Edge e in graph.OutEdges(v))
  22.                     {
  23.                         if (colors[e.To] == k)
  24.                         {
  25.                             isColorUsed = true;
  26.                             break;
  27.                         }                
  28.                     }
  29.                     if (!isColorUsed)
  30.                     {
  31.                         colors[v] = k;
  32.                         break;
  33.                     }
  34.                 }
  35.                 if (colors[v]==int.MaxValue)
  36.                 {
  37.                     maxColor++;
  38.                     colors[v] = maxColor;
  39.                 }
  40.             }
  41.             return maxColor + 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement