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
#include <stdio.h>
#include <math.h>

int n,m,k;
int zal[302][302];	// r = zal[y][0] przechowuje deg_in(y), 
					// kolejne liczby zal[y][1], zal[y][2],...,zal[y][r] - to poczatki krawedzi (x -> y)
					
int zan[302][302];	// s = zal[x][0] przechowuje deg_out(x), 
					// kolejne liczby zal[x][1], zal[x][2],...,zal[x][s] - to konce krawedzi (x -> y)				
					
int tmp[302][302];  // kopia

void wczytaj()
{
	int i,x,y,r,s;
	
	scanf("%d %d %d",&n,&m,&k);
	for(i=1;i<=m;++i)
	{
		scanf("%d %d",&x,&y);
		r = ++(zal[y][0]);
		zal[y][r] = x;
	
		s = ++(zan[x][0]);
		zan[x][s] = y;
	}

	
//	for(y=1;y<=n;++y)
//		std::sort(zal[y]+1, zal[y]+n-1, std::greater<int>());
	
	for(y=1;y<=n;++y)
		for(i=0;i<=zal[y][0];++i)
			tmp[y][i]=zal[y][i];
	
	return;
}



int licz_max(void)
{
	int i,mm,y,r,S[301];
	
	mm = 0;
	for(i=0;i<301;++i) S[i]=0;
	
	for(y=2;y<=n;y++)
	{
		r = 0;
		for(i=1;i<=zal[y][0];++i)
			if(r < 1+S[zal[y][i]]) r = 1 + S[zal[y][i]];
		S[y] = r;
		if(mm<r) mm = r;
	}
	return mm;
}



int k0(void)
{
	return licz_max() + 1;
}


int k1(void)
{
    int mm;

	mm = licz_max() + 1;

	if (n==1) return 0;
	if (mm==1) return 1;
	if(n<=3) return 1; 
	if(n<=6) return 2;
	
	if (mm-(int)(sqrt(sqrt(3*n/2)))>0) return mm-(int)(sqrt(sqrt(3*n/2))); else return 1;
}

int k2(void)
{
    int mm;

	mm = licz_max() + 1;

	if (n<=2) return 0;
	if (mm==1) return 1;
	if(n<=4) return 1; 
	if(n<=7) return 2;
	
	if (mm-(int)(sqrt(sqrt(3*n/2)))>0) return mm-(int)(sqrt(sqrt(3*n/2))); else return 1;
}

int k3(void)
{
    int mm;

	mm = licz_max() + 1;

	if (n<=3) return 0;
	if (mm==1) return 1;
	if(n<=4) return 1; 
	if(n<=7) return 2;
	
	if (mm-(int)(sqrt(sqrt(3*n/2)))>0) return mm-(int)(sqrt(sqrt(3*n/2))); else return 1;
}


int k4(void)
{
    int mm;

	mm = licz_max() + 1;

	if (n<=4) return 0;
	if (mm==1) return 1;
	if(n<=5) return 1; 
	if(n<=8) return 2;
	
	if (mm-(int)(sqrt(sqrt(2*n)))>0) return mm-(int)(sqrt(sqrt(2*n))); else return 1;
}


int main()
{
	wczytaj();
	if(k==0) printf("%d\n",k0());
	if(k==1) printf("%d\n",k1());
	if(k==2) printf("%d\n",k2());
	if(k==3) printf("%d\n",k3());
	if(k==4) printf("%d\n",k4());
			
	return 0;
}