Advertisement
kraxor

6. kotprog

Nov 25th, 2011
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct {
  5.     int gyerekszam;
  6.     int *gyerek;
  7. } csucs_t;
  8. csucs_t *csucs;
  9.  
  10. int magassag(int akt) {
  11.     if (csucs[akt].gyerekszam == 0) {
  12.         return 0;
  13.     }
  14.  
  15.     int i, max;
  16.     for (i = 0, max = 0; i < csucs[akt].gyerekszam; i++) {
  17.         int tmp = magassag(csucs[akt].gyerek[i] - 1);
  18.         if (tmp > max) {
  19.             max = tmp;
  20.         }
  21.     }
  22.  
  23.     return 1 + max;
  24. }
  25.  
  26. int main() {
  27.     FILE *be = fopen("be.txt", "r");
  28.  
  29.     int N;
  30.     fscanf(be, "%d", &N);
  31.     csucs = (csucs_t *) malloc(sizeof(csucs_t) * N);
  32.  
  33.     int i, j, K;
  34.     for (i = 0; i < N; i++) {
  35.         fscanf(be, "%d", &K);
  36.         csucs[i].gyerekszam = K;
  37.         csucs[i].gyerek = (int *) malloc(sizeof(int) * K);
  38.         for (j = 0; j < K; j++) {
  39.             fscanf(be, "%d", &csucs[i].gyerek[j]);
  40.         }
  41.     }
  42.  
  43.     int h = magassag(0);
  44.  
  45.     FILE *ki = fopen("ki.txt", "w");
  46.     fprintf(ki, "%d\n", h);
  47.     fclose(ki);
  48.  
  49.     return 0;
  50. }
  51.  
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement