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

using namespace std;
using i64 = long long;
using i32 = int;

template<typename T> T load() { T x; cin >> x; return x; }
template<typename T> vector<T> loadN(int s) { vector<T> vt(s); for(auto& el : vt) el = load<T>(); return vt; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& vt) { for(auto& el : vt) os << el << ' '; return os; }

struct Graph {
	Graph(i32 size):edges(size) {}
	void addEdge(i32 i, i32 j) { edges[i].push_back(j); }
	i32 size() const { return (i32) edges.size(); }
	vector<vector<i32>> edges;
};

Graph loadGraph(i32 v, i32 e) {
	auto g = Graph(v);
	while(e --> 0) {
		auto f = load<i32>() - 1;
		auto t = load<i32>() - 1;
		g.addEdge(f, t);
	}
	return g;
}

i32 countScore(const Graph& g, vector<bool>& isBanned, vector<i32>& dyn) {
	auto score = -1;
	const i32 size = g.size();
	for(i32 i = 0 ; i < size ; ++i) {
		if(isBanned[i]) continue;
		score = max(score, dyn[i]);
		for(auto& to : g.edges[i]) {
			if(isBanned[to]) continue;
			dyn[to] = max(dyn[to], dyn[i] + 1);
		}
	}
	fill(dyn.begin(), dyn.end(), 0);
	return score + 1;
}
template<typename T> void minEqual(T& x, const T& y) { x = min(x, y); }
#define FOR(name, start) for(i32 name = start ; name < size ; ++name)

i32 forOne(const Graph& g, vector<bool>& banned, vector<i32>& dyn) {
	const auto size = g.size();
	auto score = size;
	FOR(i, 0) {
		banned[i] = true;
		minEqual(score, countScore(g, banned, dyn));
		banned[i] = false;
	}
	return score;
}

i32 forTwo(const Graph& g, vector<bool>& banned, vector<i32>& dyn) {
	const auto size = g.size();
	auto score = size;
	FOR(i, 0) {
		banned[i] = true;
		FOR(j, i + 1) {
			banned[j] = true;
			minEqual(score, countScore(g, banned, dyn));
			banned[j] = false;
		}
		banned[i] = false;
	}
	return score;
}

i32 forThree(const Graph& g, vector<bool>& banned, vector<i32>& dyn) {
	const auto size = g.size();
	auto score = size;
	FOR(i, 0) {
		banned[i] = true;
		FOR(j, i + 1) {
			banned[j] = true;
			FOR(k, j + 1) {
				banned[k] = true;
				minEqual(score, countScore(g, banned, dyn));
				banned[k] = false;
			}
		
			banned[j] = false;
		}
		banned[i] = false;
	}
	return score;
}

i32 forFour(const Graph& g, vector<bool>& banned, vector<i32>& dyn) {
	const auto size = g.size();
	auto score = size;
	FOR(i, 0) {
		banned[i] = true;
		FOR(j, i + 1) {
			banned[j] = true;
			FOR(k, j + 1) {
				banned[k] = true;
				FOR(l, k + 1) {
					banned[l] = true;
					minEqual(score, countScore(g, banned, dyn));
					banned[l] = false;
				}
				banned[k] = false;
			}
			banned[j] = false;
		}
		banned[i] = false;
	}
	return score;
}


i32 main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	auto graphSize = load<i32>();
	auto edgeNum  = load<i32>();
	auto canErase = load<i32>();
	auto g = loadGraph(graphSize, edgeNum);
	auto dyn = vector<i32>(graphSize);
	auto banned = vector<bool>(graphSize);
	auto solve = [&](i32 k) {
		if(k == 0) return countScore(g, banned, dyn);
		if(k == 1) return forOne(g, banned, dyn);
		if(k == 2) return forTwo(g, banned, dyn);
		if(k == 3) return forThree(g, banned, dyn);
		return forFour(g, banned, dyn);
	};
	cout << solve(canErase) << '\n';
}