using System;

using System.Collections.Generic;

using static System.Console;


public class treeNode

{

    public int childN;

    public List<treeNode> branch;

    public treeNode()

    {

        childN = 0;

    }

}


public class program

{

    static void Main()

    {

        int N;

        N = int.Parse(ReadLine());

        int[] ii = new int[N];

        treeNode[] TN = new treeNode[N];

        string input = ReadLine();

        string[] inputArr = input.Split();

        for(int i =0;i<N;i++)

        {

            ii[i] = int.Parse(inputArr[i]);

            WriteLine(ii[i]);

            if(ii[i] != -1)

            {

                TN[ii[i]].childN++;     /////////   <<<<<------

                TN[ii[i]].branch.Add(TN[i]);

            }

        }

    }

}




언어 C#인데 저기 주석처리한곳에서 nullreference가 일어나

확인해보니까 TN[]이 null인거같아 근데 나 초보라 왜 그런건지 모르겠어

비슷하게 공간만든 ii[]는 null이 아니야 누가 좀 도와줘