using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication7 { class Program { static void Main(string[] args) { const int edge_count = 5; int head_count = 4; int[] edge_start = new int[edge_count] {1,0,3,0,3}; int[] edge_end = new int[edge_count] {2,3,1,1,2}; int[] head_list = new int[head_count]; int[] list_list = new int[edge_count]; int[] rez = new int[edge_start.Length+1]; for (int i = 0; i < edge_start.Length; i++) { rez[edge_start[i]+1]++; } for (int i = 1; i < rez.Length; i++) { rez[i] = rez[i] + rez[i - 1]; } int[] sorted_edge_start = new int[edge_count]; int[] sorted_edge_end = new int[edge_count]; for (int i = 0; i < edge_start.Length; i++) { int offset = rez[edge_start[i]]; rez[edge_start[i]]++; sorted_edge_start[offset] = edge_start[i]; sorted_edge_end[offset] = edge_end[i]; } for (int i = 0; i < head_list.Length; i++) { head_list[i] = -1; } for (int i = 0; i < list_list.Length; i++) { list_list[i] = -1; } for (int i = 0; i < edge_start.Length; i++) { list_list[i] = head_list[edge_start[i]]; head_list[edge_start[i]] = i; } } } }