My issue
program is ok …but it showing hidden test fail why??
My code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int n;
scanf("%d", &n);
// Dynamically allocating memory for the adjacency matrix
int **adjMatrix = (int **)malloc(n * sizeof(int *));
for (int i = 0; i < n; i++) {
adjMatrix[i] = (int *)malloc(n * sizeof(int));
// Initializing all elements to zero
memset(adjMatrix[i], 0, n * sizeof(int));
}
// Taking input for all the edges
int u, v;
for (int i = 0; i < n - 1; i++) {
scanf("%d %d", &u, &v);
// Adding an edge from u to v
adjMatrix[u][v] = 1;
}
// Printing the adjacency matrix
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
printf("%d ", adjMatrix[i][j]);
}
printf("\n");
}
// Freeing the allocated memory
for (int i = 0; i < n; i++) {
free(adjMatrix[i]);
}
free(adjMatrix);
return 0;
}
Learning course: BCS301: Data structures
Problem Link: https://www.codechef.com/learn/course/abesit-dsa/ABESITDS28/problems/DSCPP82