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
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define int4 int32_t
#define LL long long
#define int LL
#define FOR(i,a,b) for (int (i) = (a) - (a > b); (i) != (b) - (a > b); (i) += ((a) < (b)) ? 1 : -1)
#define REP(b) FOR(i, 0, b)
#define REP1(b) FOR(i, 1, (b)+1)
#define REV(b) FOR(i, b, 0)
#define REV1(b) FOR(i, (b)+1, 1)
#define ITER(i, b) for (auto (i) : (b))
#define ALL(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define VI vector<int>
#define PII pair<int,int>
#define LD long double

template<class C> void minu(C& a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxu(C& a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<","; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream &os, vector<T> V){
    os<<"[";for(auto vv:V)os<<vv<<",";return os<<"]";
} 

template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.fst << "," << P.snd << ")";
}


#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int n, m;

int wyn=1000000;

bool wyw[500];

vector <PII> kraw;

int XX_cnt;

VI graf_all[5][500];
int maxdl_all[5][500];
VI graf[550];
void backtrack(int k)
{
    debug("back", k);
    //auto &graf = graf_all[k];
    auto &maxdl=maxdl_all[k];
    int SUP=0;
    REP(n)
    {
        //graf[i].clear();
        if(!wyw[i]) maxdl[i]=1;
        else maxdl[i]=0;
    }
    /*
    ITER(kr, kraw)
    {
        if(!wyw[kr.fst] && !wyw[kr.snd])
        {
            graf[kr.fst].pb(kr.snd);
        }
    }//*/
    FOR(i, n, 0)
    {
        if(wyw[i]) continue;
        debug(graf[i]);
        ITER(j, graf[i])
        {
            maxu(maxdl[i], maxdl[j]+1);
        }
        maxu(SUP, maxdl[i]);
        debug(maxdl[i], i);
    }
    debug(SUP);
    minu(wyn, SUP);
    
    if(k>0)
    {
        int poz=0;
        REP(n)
        {
            poz=i;
            if(maxdl[poz]==SUP && !wyw[poz])
            {
                break;
            }
        }
        while(poz<500)
        {
            int tmp=wyw[poz];
            wyw[poz]=1;
            backtrack(k-1);
            wyw[poz]=tmp;
            if(maxdl[poz]==1) break;
            ITER(i, graf[poz])
            {
                if(maxdl[i]+1==maxdl[poz])
                {
                    poz=i;
                    break;
                }
            }
        }
    }
    //else {XX_cnt++; if(XX_cnt >100 && XX_cnt==(XX_cnt&(-XX_cnt)))fprintf(stderr, "cnt=%lld\n", XX_cnt);}
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    int k;
    srand(time(0));
    scanf("%lld%lld%lld", &n, &m, &k);
    /*map <PII, bool> jest;
    srand(time(0));
    int count=0;
    while(count<m)
    {
        int x = rand()%n;
        int y = rand()%n;
        if(x < y && jest.find(mp(x, y)) == jest.end())
        {
            kraw.pb(mp(x, y));
            jest[mp(x, y)]=1;
            count ++;
        }
    }//*/
    //*
    REP(m)
    {
        int x, y;
        scanf("%lld%lld", &x, &y);
        x--;
        y--;
        graf[x].pb(y);
        kraw.pb(mp(x, y));
    }//*/
    debug(kraw);
    backtrack(k);
    printf("%lld\n", wyn);
}