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
78
79
80
81
#include<bits/stdc++.h>

using namespace std;

vector<int> tos[309];
int tab[309];

vector<int> nsciezka;
int rem[309];
vector<int> krem;

int n, m;

void sciezkemam(int pos){
    nsciezka.push_back(pos);
    for(int i=0;i<tos[pos].size();++i){
        if(rem[tos[pos][i]]==1)continue;
        if(tab[tos[pos][i]]== tab[pos]-1){sciezkemam(tos[pos][i]);break;}
    }
}

int licz(int pos){
    if(rem[pos]==1)return -1;
    if(tab[pos]!=0)return tab[pos];
    for(int i=0;i<tos[pos].size();++i){
        tab[pos]=max(tab[pos], licz(tos[pos][i])+1);
    }
    return tab[pos];
}

vector<int> findsciezka(){
    int mdl=-1;
    int pos=0;
    for(int i=1;i<=n;++i)tab[i]=0;
    for(int i=1;i<=n;++i){
        if(rem[i]==1)continue;
        int temp=licz(i);
        if(temp>mdl){
            pos=i;
            mdl=temp;
        }
    }
    nsciezka.clear();
    if(pos!=0)sciezkemam(pos);
    return nsciezka;
}


int dfs(int k){
    int ret=1000;
    vector<int> sciezka = findsciezka();//cerr<<sciezka.size()<<endl;
    //for(int i=0;i<sciezka.size();++i)cerr<<sciezka[i]<<" ";
    //cerr<<endl;
    //for(int i=0;i<krem.size();++i)cerr<<krem[i]<<" ";
    //cerr<<"\n\n";
    if(k == 0)return sciezka.size();
    for(int i=0;i<sciezka.size();++i){
        krem.push_back(sciezka[i]);
        rem[sciezka[i]]=1;
        ret=min(ret, dfs(k-1));
        rem[sciezka[i]]=0;
        krem.pop_back();
    }

    return ret;
}

int main(){
    ios_base::sync_with_stdio(0);
    int k;cin>>n>>m>>k;
    srand(time(0));

    for(int i=0;i<m;++i){
        int a, b;cin>>a>>b;
        tos[a].push_back(b);
    }

    cout<<dfs(k)<<endl;

    return 0;
}