Submission #2999749


Source Code Expand

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

namespace AtTest.C_Challenge.ABC_021
{
    class ABC_021
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0])-1;
            int b = int.Parse(input[1])-1;
            int m= int.Parse(Console.ReadLine());
            var nodes = new Node[n];
            for(int i = 0; i < n; i++)
            {
                nodes[i] = new Node();
            }

            for (int i = 0; i < m; i++)
            {
                input = Console.ReadLine().Split(' ');
                int x = int.Parse(input[0]) - 1;
                int y = int.Parse(input[1]) - 1;
                nodes[x].edges.Add(new Edge(y, 1));
                nodes[y].edges.Add(new Edge(x, 1));
            }

            nodes[a].distance = 0;
            nodes[a].patterns = 1;
            var posQueue = new Queue<int>();
            posQueue.Enqueue(a);

            while (posQueue.Count > 0)
            {
                int index = posQueue.Dequeue();
                long distance = nodes[index].distance + 1;

                for (int i = 0; i < nodes[index].edges.Count; i++)
                {
                    int targetIndex = nodes[index].edges[i].toIndex;
                    long targetDistance = nodes[targetIndex].distance;
                    if (targetDistance == -1 || distance < targetDistance)
                    {
                        nodes[targetIndex].distance = distance;
                        posQueue.Enqueue(targetIndex);
                        nodes[targetIndex].patterns = nodes[index].patterns;
                    }
                    else if (distance == targetDistance)
                    {
                        nodes[targetIndex].patterns
                            = (nodes[targetIndex].patterns
                            + nodes[index].patterns) % 1000000007;
                    }
                }
            }
            Console.WriteLine(nodes[b].patterns);
        }
    }

    class Node
    {
        public long distance;
        public long patterns;
        public List<Edge> edges;
        public Node(bool isStart = false)
        {
            distance = isStart ? 0 : -1;
            patterns = 0;
            edges = new List<Edge>();
        }
    }

    class Edge
    {
        public int toIndex;
        public int distance;

        public Edge(int toIndex, int distance)
        {
            this.toIndex = toIndex;
            this.distance = distance;
        }
    }
}

Submission Info

Submission Time
Task C - 正直者の高橋くん
User MiuraMiuMiu
Language C# (Mono 4.6.2.0)
Score 100
Code Size 2856 Byte
Status AC
Exec Time 23 ms
Memory 13396 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 32
Set Name Test Cases
Sample subtask0_sample_01.txt, subtask0_sample_02.txt
All subtask0_sample_01.txt, subtask0_sample_02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt, subtask1_23.txt, subtask1_24.txt, subtask1_25.txt, subtask1_26.txt, subtask1_27.txt, subtask1_28.txt, subtask1_29.txt, subtask1_30.txt
Case Name Status Exec Time Memory
subtask0_sample_01.txt AC 23 ms 11348 KB
subtask0_sample_02.txt AC 22 ms 9300 KB
subtask1_01.txt AC 23 ms 13396 KB
subtask1_02.txt AC 22 ms 9300 KB
subtask1_03.txt AC 22 ms 9300 KB
subtask1_04.txt AC 23 ms 11348 KB
subtask1_05.txt AC 22 ms 9300 KB
subtask1_06.txt AC 22 ms 9300 KB
subtask1_07.txt AC 23 ms 11348 KB
subtask1_08.txt AC 22 ms 9300 KB
subtask1_09.txt AC 23 ms 11348 KB
subtask1_10.txt AC 23 ms 11348 KB
subtask1_11.txt AC 23 ms 11348 KB
subtask1_12.txt AC 22 ms 9300 KB
subtask1_13.txt AC 23 ms 11348 KB
subtask1_14.txt AC 22 ms 9300 KB
subtask1_15.txt AC 23 ms 11348 KB
subtask1_16.txt AC 22 ms 9300 KB
subtask1_17.txt AC 23 ms 9300 KB
subtask1_18.txt AC 22 ms 9300 KB
subtask1_19.txt AC 22 ms 9300 KB
subtask1_20.txt AC 22 ms 9300 KB
subtask1_21.txt AC 22 ms 9300 KB
subtask1_22.txt AC 23 ms 11348 KB
subtask1_23.txt AC 23 ms 11348 KB
subtask1_24.txt AC 22 ms 9300 KB
subtask1_25.txt AC 22 ms 9300 KB
subtask1_26.txt AC 23 ms 11348 KB
subtask1_27.txt AC 23 ms 9300 KB
subtask1_28.txt AC 22 ms 9300 KB
subtask1_29.txt AC 22 ms 9300 KB
subtask1_30.txt AC 22 ms 9300 KB