Submission #69472048


Source Code Expand

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

#pragma warning disable CS8603, CS8604, CS8602


namespace ProblemC
{
    internal class TEST
    {
        public static void Main()
        {
            Sol mySol = new Sol();
            mySol.Solve();
        }
    }

    internal class Sol
    {
        public void Solve()
        {
            var E = new List<int>[N];
            for (int i = 0; i < N; i++) E[i] = new List<int>();

            int[] min = mka<int>(N, -1);
            var q = new Queue<int>();
            for(int i=0;i<N;i++){
                if(A[i] == -1 && B[i] == -1){
                    min[i] = 0;
                    q.Enqueue(i);
				} else {
                    E[A[i]].Add(i);
                    E[B[i]].Add(i);
				}
            }

            while(q.Count > 0){
                var v = q.Dequeue();
                foreach(var u in E[v]){
                    if(min[u] < 0){
                        min[u] = min[v] + 1;
                        q.Enqueue(u);
					}
                }
            }
            int ans = 0;
            for(int i=0;i<N;i++) if(min[i] != -1) ans++;
            Console.WriteLine(ans);
		}
        int N;
        int[] A, B;
        public Sol()
        {
            N = ri();
            A = new int[N];
            B = new int[N];
            for(int i=0;i<N;i++){
                var d = ria();
                A[i] = d[0] - 1;
                B[i] = d[1] - 1;
			}
        }

        static String rs() { return Console.ReadLine(); }
        static int ri() { return int.Parse(Console.ReadLine()); }
        static long rl() { return long.Parse(Console.ReadLine()); }
        static double rd() { return double.Parse(Console.ReadLine()); }
        static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
        static T[] mka<T>(int n, T ini) { T[] ret = new T[n]; for (int i = 0; i < n; i++) ret[i] = ini; return ret; }
        static T[][] mka<T>(int n, int m, T ini) { T[][] ret = new T[n][]; for (int i = 0; i < n; i++) ret[i] = mka(m, ini); return ret; }
        static T[][][] mka<T>(int n, int m, int l, T ini) { T[][][] ret = new T[n][][]; for (int i = 0; i < n; i++) ret[i] = mka(m, l, ini); return ret; }
        static T[][][][] mka<T>(int n, int m, int l, int k, T ini) { T[][][][] ret = new T[n][][][]; for (int i = 0; i < n; i++) ret[i] = mka(m, l, k, ini); return ret; }

    }

}

Submission Info

Submission Time
Task C - New Skill Acquired
User kuuso
Language C# 11.0 (.NET 7.0.7)
Score 300
Code Size 2910 Byte
Status AC
Exec Time 152 ms
Memory 61692 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 30
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All hand_01.txt, hand_02.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
hand_01.txt AC 42 ms 25000 KiB
hand_02.txt AC 47 ms 25216 KiB
random_01.txt AC 125 ms 61188 KiB
random_02.txt AC 46 ms 27664 KiB
random_03.txt AC 138 ms 61536 KiB
random_04.txt AC 107 ms 56924 KiB
random_05.txt AC 141 ms 61640 KiB
random_06.txt AC 105 ms 56436 KiB
random_07.txt AC 152 ms 61692 KiB
random_08.txt AC 97 ms 58716 KiB
random_09.txt AC 134 ms 61440 KiB
random_10.txt AC 138 ms 61268 KiB
random_11.txt AC 109 ms 61148 KiB
random_12.txt AC 138 ms 61180 KiB
random_13.txt AC 129 ms 61168 KiB
random_14.txt AC 136 ms 61068 KiB
random_15.txt AC 139 ms 61124 KiB
random_16.txt AC 70 ms 49736 KiB
random_17.txt AC 133 ms 60748 KiB
random_18.txt AC 56 ms 31632 KiB
random_19.txt AC 80 ms 49496 KiB
random_20.txt AC 109 ms 60160 KiB
random_21.txt AC 37 ms 25876 KiB
random_22.txt AC 53 ms 37004 KiB
random_23.txt AC 125 ms 56740 KiB
random_24.txt AC 54 ms 39444 KiB
random_25.txt AC 83 ms 49916 KiB
random_26.txt AC 46 ms 28072 KiB
sample_01.txt AC 47 ms 25228 KiB
sample_02.txt AC 43 ms 25220 KiB