Розділи нашого сайту


1.Новини
2.Про gpd
3.Скарги учасників
4.Розв"язки та алґоритми gpd
5.Тести
6.Гістьова книга
7.Лінки
#include<stdio.h>
#include<stdlib.h>
#include<string.h>


#define MAXN            205

#define MAXM            40000L
#define uchar unsigned char
#define LONG_MAX  32000

int main(void)
{
  unsigned short N, p, q, K, x, y;
  unsigned short h = 0;
  unsigned short i, j, _min = LONG_MAX;
  unsigned short l = 0;
  bool smth;
  unsigned short ne[MAXM];
  uchar el[MAXM];
  unsigned short f[MAXN];
  uchar s[MAXN];
  uchar a[MAXN];
  unsigned short FORLIM, FORLIM1;

  memset(&f, 0, sizeof(f));
  scanf("%hd%hd", &N, &K);
  FORLIM = K;
  for (i = 1; i <= FORLIM; i++) {
    scanf("%hd%hd", &x, &y);
    h++;
    el[h-1] = y;
    ne[h-1] = f[x-1];
    f[x-1] = h;
  }
  if (stdin != NULL)
    fclose(stdin);
  stdin = NULL;
  FORLIM = N;
  for (i = 1; i <= FORLIM; i++) {
    p = 1;
    q = 1;
    s[0] = i;
    memset(&a, 0, sizeof(a));
    a[i-1] = 1;
    while (p <= q) {
      x = f[s[p-1] - 1];
      while (x != 0) {
	if (a[el[x-1] - 1] == 0) {
	  a[el[x-1] - 1] = a[s[p-1] - 1] + 1;
	  q++;
	  s[q-1] = el[x-1];
	}
	x = ne[x-1];
      }
      p++;
    }
    smth = false;
    FORLIM1 = N;
    for (j = 1; j <= FORLIM1; j++) {
      if (a[j-1] == 0) {
	smth = true;
	break;
      }
    }
    if (!smth && a[s[q-1] - 1] < _min) {
      _min = a[s[q-1] - 1];
      l = i;
    }
  }
  printf("%u
", l);
  return 0;
}



generated by gpd hackers group (c) 2004
Hosted by uCoz