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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Kurenkov
{
class Program
{
public class ArcList
{
public int[] I, J, L, H;
public ArcList(int defaultCapacity)
{
this.I = new int[defaultCapacity];
this.J = new int[defaultCapacity];
this.L = new int[defaultCapacity];
this.H = new int[defaultCapacity];
for (int i = 0; i < defaultCapacity; ++i)
{
this.H[i] = -1;
}
}
}
static void Main(string[] args)
{
int[,] input = new int[6, 2] {{3, 4}, {0, 1}, {0, 3}, {2, 4}, {4, 1}, {1, 2}};
int n = 5, m = 6; //n - number of vertices, m - number of arcs;
ArcList lol = new ArcList(m);
for (int i = 0; i < m; ++i)
{
lol.I[i] = input[i, 0];
lol.J[i] = input[i, 1];
}
for (int i = 0; i < m; ++i)
{
lol.L[i] = lol.H[lol.I[i]];
lol.H[lol.I[i]] = i;
}
Console.WriteLine("L");
for (int i = 0; i < m; ++i)
{
Console.WriteLine(lol.L[i]);
}
Console.WriteLine();
Console.WriteLine("H");
for (int i = 0; i < n; ++i)
{
Console.WriteLine(lol.H[i]);
}
}
}
}