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
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
const int N = 305;
int n, m, k, x, y, dp[N], ans = N, skad[N], dd;
bool usun[N];
vector<int> v[N], empt;
int wynik()
{
        int ans = 0;
        for(int i=n;i>0;i--)
        {
                dp[i] = 0;
                skad[i] = 0;
                if(!usun[i])
                {
                        for(auto x : v[i]) if(!usun[x])
                        {
                                if(dp[i] < dp[x])
                                {
                                        dp[i] = dp[x];
                                        skad[i] = x;
                                }
                        }
                        dp[i]++;
                        ans = max(ans, dp[i]);
                }
        }
        return ans;
}
vector<int> find()
{
        empt.clear();
        int x = 1;
        while(dp[x]!=dd) x++;
        while(skad[x])
        {
                empt.push_back(x);
                x = skad[x];
        }
        empt.push_back(x);
        return empt;
}
void rec(int l)
{
        dd = wynik();
        if(l==0)
        {
                ans = min(ans, dd);
                return;
        }
        vector<int> s = find();
        for(auto i : s)
        {
                usun[i] = 1;
                rec(l - 1);
                usun[i] = 0;
        }
}
int main()
{
        scanf("%d%d%d", &n, &m, &k);
        while(m--)
        {
                scanf("%d%d", &x, &y);
                v[x].push_back(y);
        }
        rec(k);
        printf("%d", ans);
        return 0;
}