Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct {
- int gyerekszam;
- int *gyerek;
- } csucs_t;
- csucs_t *csucs;
- int magassag(int akt) {
- if (csucs[akt].gyerekszam == 0) {
- return 0;
- }
- int i, max;
- for (i = 0, max = 0; i < csucs[akt].gyerekszam; i++) {
- int tmp = magassag(csucs[akt].gyerek[i] - 1);
- if (tmp > max) {
- max = tmp;
- }
- }
- return 1 + max;
- }
- int main() {
- FILE *be = fopen("be.txt", "r");
- int N;
- fscanf(be, "%d", &N);
- csucs = (csucs_t *) malloc(sizeof(csucs_t) * N);
- int i, j, K;
- for (i = 0; i < N; i++) {
- fscanf(be, "%d", &K);
- csucs[i].gyerekszam = K;
- csucs[i].gyerek = (int *) malloc(sizeof(int) * K);
- for (j = 0; j < K; j++) {
- fscanf(be, "%d", &csucs[i].gyerek[j]);
- }
- }
- int h = magassag(0);
- FILE *ki = fopen("ki.txt", "w");
- fprintf(ki, "%d\n", h);
- fclose(ki);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement