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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
#include<vector>
#include<set>
#include<queue>

/*
Autor: Helena Borak-Wejster
*/
using namespace std;

void refresh(set<int> to_delete, vector<vector<int>>& v,int n){
    for(int j=0;j<n;j++){
        if(to_delete.count(j)){
            v[j].clear();
        }
        else{
            for(int i=0;i<v[j].size();i++){
                if(to_delete.count(v[j][i])!=0){
                    v[j].erase(v[j].begin()+i,v[j].begin()+i+1);
                }
            }
        }
        /* if(to_delete.count(j)){
            out[j].clear();
        }
        else{
            for(int i=0;i<out[j].size();i++){
                if(to_delete.count(out[j][i])!=0){
                    out[j].erase(out[j].begin()+i,out[j].begin()+i+1);
                }
            }
        }
    }*/
    }
}


int main()
{
    int n,m,k;
    cin >> n >> m >> k;
    vector<vector<int>> out(n);
    vector<vector<int>> in(n);
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        out[a-1].push_back(b-1);
        in[b-1].push_back(a-1);
    }
    priority_queue<pair<int,int>> Q;
    for(int i=0;i<n;i++){
        Q.push(make_pair((in[i].size()+out[i].size()),i));
    }
    set<int> to_delete;
    for(int i=0;i<k;i++){
        pair<int,int> tmp = Q.top();
        Q.pop();
        to_delete.insert(tmp.second);
        //cout << tmp.second <<endl;
    }
    refresh(to_delete,in,n);
    refresh(to_delete,out,n);
    /*priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>> > topologic;
    for(int i=0;i<n;i++){
        if(to_delete.count(i)==0) topologic.push(make_pair(in[i].size(),i));
    }
    int top = topologic.top();
    while(top)*/
    /*cout << "graf"<<endl;
    for(int ind=0;ind<n;ind++){
        cout << ind << endl;
    for(auto j=out[ind].begin();j!=out[ind].end();j++){
        cout << *j << " ";
    }
    cout << "out"<<endl;
    for(auto j=in[ind].begin();j!=in[ind].end();j++){
        cout << *j << " ";
    }
    cout << "in"<<endl;
    }*/

    int max_sc = 0;
    for(int i=0;i<n;i++){
        queue<pair<int,int>> qu;
        qu.push(make_pair(i,1));
        while(!qu.empty()){
            pair<int,int> p = qu.front();
            int ind = p.first;
            qu.pop();
            for(auto j=out[ind].begin();j!=out[ind].end();j++){
                max_sc=max(max_sc,p.second+1);
                qu.push(make_pair(*j,p.second+1));
            }
        }
    }
    cout << max_sc << endl;
    return 0;
}