UVa 11363 - Cuckoo Hashing

int ht[10000];

main {	int nums, m, n, i, j, x, y, z, need, k, min, stat;

scanf("%d", &nums); for (nums--;) {		scanf("%d%d", &m, &n);

stat = 0; memset(ht, -1, sizeof(ht)); for (i = 0; i < m; i++) {			scanf("%d%d", &x, &y); if (stat) {				continue; }

if (x > n || y > n)			{ stat = 1; continue; }

if (ht[x] != -1) {				if (ht[y] != -1) {					stat = 1; continue; }				else {					ht[y] = i;				} }			else {				ht[x] = i;			} }

stat?puts("rehash necessary"):puts("successful hashing"); } }