using System using System Collections Generic using System Linq using

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Comb_Ancestors
{
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[] edge_start = new int[edge_count] { 0, 1, 2, 1, 0 };
int[] edge_end = new int[edge_count] { 1, 2, 3, 3, 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;
}
Console.WriteLine();
}
}
}