Submission #287413


Source Code Expand

Copy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static int n;
    static int x;
    static int[] h;
    static int[][] ab;
    static Queue<int[]> q;
    static bool[] mask;

    static void Main(string[] args)
    {
        int[] tmp = GetIntArray();
        int answer = 0;
        n = tmp[0];
        x = tmp[1];
        h = GetIntArray();
        mask = new bool[n];
        ab = new int[n][];
        for (int i = 0;i < n-1 ;i++ )
        {
            ab[i] = GetIntArray();
        }
        answer = Search(0,x);
        Console.WriteLine(answer);
        Console.Read();
    }

    public static int Search(int depth, int startNode)
    {
        mask[startNode] = true;
        for (int i = 0;i < n-1 ;i++ )
        {
            if (!mask[ab[i][1]] && !mask[ab[i][1]])
            {
                if (h[ab[i][1] - 1] == 1)
                {
                    return depth * 2;
                }
                mask[startNode] = true;
                return Search(depth + 1, ab[i][1]);
                if (h[ab[i][0] - 1] == 1)
                {
                    return depth * 2;
                }
                mask[startNode] = true;
                return Search(depth + 1, ab[i][0]);
            }

        }
        return 0;
    }


#region DATA_READ_SUPPORT
    static string[] GetStrArray()
    {
        return Console.ReadLine().Split(' ');
    }

    static int[] GetIntArray()
    {

        string[] s = GetStrArray();
        int[] a = new int[s.Length];
        for(int i= 0; i < a.Length; i++)
        {
            a[i] = int.Parse(s[i]);
        }
        return a;
    }

    static int GetInt()
    {
        return int.Parse(Console.ReadLine());
    }

    static double[] GetDoubleArray()
    {

        string[] s = GetStrArray();
        double[] a = new double[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = double.Parse(s[i]);
        }
        return a;
    }

    static double GetDouble()
    {
        return double.Parse(Console.ReadLine());
    }
#endregion DATA_READ_SUPPORT
}

Submission Info

Submission Time
Task B - ツリーグラフ
User pekoong
Language C# (Mono 2.10.8.1)
Score 0
Code Size 2259 Byte
Status WA
Exec Time 169 ms
Memory 8904 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
WA × 1
RE × 1
WA × 13
RE × 7
Set Name Test Cases
Sample subtask0_sample_01.txt, subtask0_sample_02.txt
All subtask0_sample_01.txt, subtask0_sample_02.txt, subtask1_line01.txt, subtask1_line02.txt, subtask1_line03.txt, subtask1_line04.txt, subtask1_line05.txt, subtask1_line06.txt, subtask1_random01.txt, subtask1_random02.txt, subtask1_random03.txt, subtask1_random04.txt, subtask1_random05.txt, subtask1_random06.txt, subtask1_random07.txt, subtask1_random08.txt, subtask1_special01.txt, subtask1_special02.txt, subtask1_special03.txt, subtask1_special04.txt
Case Name Status Exec Time Memory
subtask0_sample_01.txt WA 155 ms 8848 KB
subtask0_sample_02.txt RE 164 ms 8844 KB
subtask1_line01.txt RE 157 ms 8764 KB
subtask1_line02.txt WA 155 ms 8860 KB
subtask1_line03.txt WA 148 ms 8840 KB
subtask1_line04.txt RE 156 ms 8900 KB
subtask1_line05.txt RE 164 ms 8884 KB
subtask1_line06.txt RE 169 ms 8900 KB
subtask1_random01.txt WA 158 ms 8856 KB
subtask1_random02.txt WA 153 ms 8852 KB
subtask1_random03.txt WA 155 ms 8856 KB
subtask1_random04.txt RE 153 ms 8904 KB
subtask1_random05.txt WA 150 ms 8864 KB
subtask1_random06.txt WA 152 ms 8856 KB
subtask1_random07.txt WA 159 ms 8856 KB
subtask1_random08.txt WA 151 ms 8844 KB
subtask1_special01.txt RE 157 ms 8764 KB
subtask1_special02.txt WA 153 ms 8852 KB
subtask1_special03.txt WA 154 ms 8860 KB
subtask1_special04.txt WA 156 ms 8856 KB