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
69
70
71
72
73
74
75
76
77
//#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>

using namespace std;

int n, m, k, a, b, l[4],wmax=301, w;

vector <int>ls[301];
int tab[301];

void sciezka()
{
	w = 0;
	for (int i = 1; i <= n; i++)
	{
		tab[i] = 1;
	}
	for (int i = 0; i < 4; i++)tab[l[i]] = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j < 4; j++)tab[l[j]] = 0;
		//printf("%d ", tab[i]);
		for (int j = ls[i].size(); j > 0; j--)
		{
			if (tab[ls[i][j - 1]] <= tab[i]&&tab[i]!=0)tab[ls[i][j - 1]] = tab[i] + 1;
		}
		if (tab[i] > w)w = tab[i];
	}
	if (w < wmax)wmax = w;
	//printf("\n%d %d %d %d %d\n", l[0], l[1], l[2], l[3], w);
}

int main()
{
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < m; i++)
	{
		scanf("%d%d", &a, &b);
		ls[a].push_back(b);
	}
	if (k == 0)sciezka();
	else
	{
		for (int i1 = 1; i1 <= n; i1++)
		{
			l[0] = i1;
			if (k == 1)sciezka();
			else
			{
				for (int i2 = i1 + 1; i2 <= n; i2++)
				{
					l[1] = i2;
					if (k == 2)sciezka();
					else
					{
						for (int i3 = i2 + 1; i3 <= n; i3++)
						{
							l[2] = i3;
							if (k == 3)sciezka();
							else
							{
								for (int i4 = i3 + 1; i4 <= n; i4++)
								{
									l[3] = i4;
									sciezka();
								}
							}
						}
					}
				}
			}
		}
	}
	printf("%d\n", wmax);
	//system("PAUSE");
}