Submission #30487303


Source Code Expand

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;

namespace Tasks
{
    public class F
    {
        public static void Main()
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var (N, M) = Scanner.Scan<int, int>();
            var G = new List<int>[N].Select(x => new List<int>()).ToArray();
            var deg = new int[N];
            for (var i = 0; i < M; i++)
            {
                var (u, v) = Scanner.Scan<int, int>();
                u--; v--;
                G[v].Add(u);
                deg[u]++;
            }

            var queue = new Queue<int>();
            for (var i = 0; i < N; i++)
            {
                if (deg[i] == 0) queue.Enqueue(i);
            }

            var answer = N;
            while (queue.Count > 0)
            {
                var u = queue.Dequeue();
                answer--;

                foreach (var v in G[u])
                {
                    deg[v]--;
                    if (deg[v] == 0) queue.Enqueue(v);
                }
            }

            Console.WriteLine(answer);
        }

        public static class Scanner
        {
            public static string ScanLine() => Console.ReadLine()?.Trim() ?? string.Empty;
            public static string[] Scan() => ScanLine().Split(' ');
            public static T Scan<T>() where T : IConvertible => Convert<T>(Scan()[0]);
            public static (T1, T2) Scan<T1, T2>() where T1 : IConvertible where T2 : IConvertible
            {
                var line = Scan();
                return (Convert<T1>(line[0]), Convert<T2>(line[1]));
            }
            public static (T1, T2, T3) Scan<T1, T2, T3>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible
            {
                var line = Scan();
                return (Convert<T1>(line[0]), Convert<T2>(line[1]), Convert<T3>(line[2]));
            }
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible
            {
                var line = Scan();
                return (Convert<T1>(line[0]), Convert<T2>(line[1]), Convert<T3>(line[2]), Convert<T4>(line[3]));
            }
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible where T5 : IConvertible
            {
                var line = Scan();
                return (Convert<T1>(line[0]), Convert<T2>(line[1]), Convert<T3>(line[2]), Convert<T4>(line[3]), Convert<T5>(line[4]));
            }
            public static (T1, T2, T3, T4, T5, T6) Scan<T1, T2, T3, T4, T5, T6>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible where T5 : IConvertible where T6 : IConvertible
            {
                var line = Scan();
                return (Convert<T1>(line[0]), Convert<T2>(line[1]), Convert<T3>(line[2]), Convert<T4>(line[3]), Convert<T5>(line[4]), Convert<T6>(line[5]));
            }
            public static IEnumerable<T> ScanEnumerable<T>() where T : IConvertible => Scan().Select(Convert<T>);
            private static T Convert<T>(string value) where T : IConvertible => (T)System.Convert.ChangeType(value, typeof(T));
        }
    }
}

Submission Info

Submission Time
Task F - Endless Walk
User AconCavy
Language C# (.NET Core 3.1.201)
Score 500
Code Size 3686 Byte
Status AC
Exec Time 252 ms
Memory 61628 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 37
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, hand_16.txt, hand_17.txt, hand_18.txt, hand_19.txt, random_00.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
Case Name Status Exec Time Memory
example_00.txt AC 77 ms 28144 KiB
example_01.txt AC 74 ms 28132 KiB
hand_00.txt AC 237 ms 59444 KiB
hand_01.txt AC 219 ms 59544 KiB
hand_02.txt AC 250 ms 59664 KiB
hand_03.txt AC 244 ms 59452 KiB
hand_04.txt AC 246 ms 59976 KiB
hand_05.txt AC 237 ms 59896 KiB
hand_06.txt AC 142 ms 47500 KiB
hand_07.txt AC 140 ms 47468 KiB
hand_08.txt AC 141 ms 47228 KiB
hand_09.txt AC 236 ms 61396 KiB
hand_10.txt AC 236 ms 61628 KiB
hand_11.txt AC 214 ms 60104 KiB
hand_12.txt AC 211 ms 60016 KiB
hand_13.txt AC 248 ms 60652 KiB
hand_14.txt AC 252 ms 60368 KiB
hand_15.txt AC 92 ms 39228 KiB
hand_16.txt AC 74 ms 28180 KiB
hand_17.txt AC 68 ms 28292 KiB
hand_18.txt AC 65 ms 28060 KiB
hand_19.txt AC 167 ms 58160 KiB
random_00.txt AC 142 ms 47524 KiB
random_01.txt AC 150 ms 47732 KiB
random_02.txt AC 158 ms 48064 KiB
random_03.txt AC 171 ms 48560 KiB
random_04.txt AC 190 ms 52136 KiB
random_05.txt AC 140 ms 47556 KiB
random_06.txt AC 149 ms 47556 KiB
random_07.txt AC 161 ms 48464 KiB
random_08.txt AC 162 ms 48836 KiB
random_09.txt AC 196 ms 52212 KiB
random_10.txt AC 140 ms 47252 KiB
random_11.txt AC 151 ms 47628 KiB
random_12.txt AC 153 ms 48468 KiB
random_13.txt AC 178 ms 51100 KiB
random_14.txt AC 223 ms 58336 KiB