Submission #420951


Source Code Expand

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

namespace AtCoderTypicalContest001
{
    class Program
    {
        static int[] dy = { 0, 1, 0, -1 };
        static int[] dx = { 1, 0, -1, 0 };
        static void A()
        {
            string[] one = Console.ReadLine().Split(' ');
            int H = int.Parse(one[0]);
            int W = int.Parse(one[1]);
            string[] map = new string[H];
            bool[,] b = new bool[H, W];
            int startx = 0;
            int starty = 0;
            int goalx = 0;
            int goaly = 0;
            for(int i = 0;i<H;i++)
            {
                map[i] = Console.ReadLine();
                for(int j = 0;j<W;j++)
                {
                    if(map[i][j] == 's')
                    {
                        startx = j;
                        starty = i;
                    }

                    if(map[i][j] == 'g')
                    {
                        goalx = j;
                        goaly = i;
                    }
                }
            }

            if(A_Dfs(startx, starty, goalx, goaly, b, map,W,H))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }

        static bool A_Dfs(int nowX,int nowY,int endX,int endY,bool[,] b,string[] map,int W,int H)
        {
            if(map[nowY][nowX] == 'g')return true;
            bool ans = false;
            for (int i = 0; i < 4; i++)
            {
                int nextx = nowX + dx[i];
                int nexty = nowY + dy[i];
                if (nextx < 0 || nextx >= W || nexty < 0 || nexty >= H) continue;
                if (b[nexty, nextx]) continue;
                if (map[nexty][nextx] == '#') continue;
                b[nexty, nextx] = true;
                ans = ans || A_Dfs(nextx, nexty, endX, endY, b, map, W, H);
            }


            return ans;
        }
        static void B()
        {
            string[] one = Console.ReadLine().Split(' ');
            int N = int.Parse(one[0]);
            int Q = int.Parse(one[1]);
            int[] numbers = new int[N + 1];
            for(int i = 1;i<N+1;i++)
            {
                numbers[i] = i;
            }

            for(int i = 0;i<Q;i++)
            {
                string[] line = Console.ReadLine().Split(' ');
                int p = int.Parse(line[0]);
                int a = int.Parse(line[1]);
                int b = int.Parse(line[2]);

                if(p == 0)
                {
                    int min = Math.Min(numbers[a],numbers[b]);
                    if(min != numbers[a])
                    {
                        numbers[a] = min;
                    }else
                    {
                        numbers[b] = min;
                    }
                }
                else
                {
                    if(numbers[a] == numbers[b])
                    {
                        Console.WriteLine("Yes");
                    }else
                    {
                        Console.WriteLine("No");
                    }
                }
            }

        }
        static void Main(string[] args)
        {
            //A();
            B();
        }
    }
}

Submission Info

Submission Time
Task B - Union Find
User tookunn
Language C# (Mono 3.2.1.0)
Score 100
Code Size 3478 Byte
Status AC
Exec Time 1826 ms
Memory 13016 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 1
AC × 19
Set Name Test Cases
Sample 00_sample_01.txt
All 00_sample_01.txt, subtask_01_01.txt, subtask_01_02.txt, subtask_01_03.txt, subtask_01_04.txt, subtask_01_05.txt, subtask_01_06.txt, subtask_01_07.txt, subtask_01_08.txt, subtask_01_09.txt, subtask_01_10.txt, subtask_01_11.txt, subtask_01_12.txt, subtask_01_13.txt, subtask_01_14.txt, subtask_01_15.txt, subtask_01_16.txt, subtask_01_17.txt, subtask_01_18.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 262 ms 8840 KB
subtask_01_01.txt AC 1133 ms 12880 KB
subtask_01_02.txt AC 105 ms 8884 KB
subtask_01_03.txt AC 1478 ms 12876 KB
subtask_01_04.txt AC 1821 ms 13016 KB
subtask_01_05.txt AC 186 ms 12920 KB
subtask_01_06.txt AC 184 ms 12980 KB
subtask_01_07.txt AC 1454 ms 12896 KB
subtask_01_08.txt AC 1734 ms 13000 KB
subtask_01_09.txt AC 103 ms 8832 KB
subtask_01_10.txt AC 104 ms 8892 KB
subtask_01_11.txt AC 1529 ms 12916 KB
subtask_01_12.txt AC 1555 ms 13016 KB
subtask_01_13.txt AC 1323 ms 12960 KB
subtask_01_14.txt AC 110 ms 8996 KB
subtask_01_15.txt AC 1666 ms 12844 KB
subtask_01_16.txt AC 1826 ms 13008 KB
subtask_01_17.txt AC 1145 ms 13008 KB
subtask_01_18.txt AC 1003 ms 13012 KB