35932023-03-01 09:30:21AGergoRácsháló gráfcsharpTime limit exceeded 28/50601ms23960 KiB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace graf
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] be = Console.ReadLine().Split();

            int n = int.Parse(be[0]);
            int m = int.Parse(be[1]);

            int k = int.Parse(be[2]);

            int[,] dist = new int[n * m + 1, n * m + 1];

            for (int i = 1; i < n*m+1; i++)
            {
                for (int j = 1; j < n * m+1; j++)
                {
                    dist[i, j] = 201;
                }
            }

            int down = 0;
            int up = 0;
            int left = 0;
            int right = 0;

            for (int i = 1; i < n*m+1; i++)
            {
                if ((i-1)/m == 0)
                {
                    up = 0;
                    down = i + m;
                }
                else if ((i-1)/m == n-1)
                {
                    up = i - m;
                    down = 0;
                }
                else
                {
                    up = i - m;
                    down = i + m;
                }

                if (i % m == 1)
                {
                    left = 0;
                    right = i + 1;
                }
                else if (i % m == 0)
                {
                    left = i - 1;
                    right = 0;
                }
                else
                {
                    left = i - 1;
                    right = i + 1;
                }
                //Console.WriteLine(i + "-" + up + " " + down + " " + left + " " + right);

                dist[i, up] = 1;
                dist[up, i] = 1;
                dist[i, down] = 1;
                dist[down, i] = 1;
                dist[i, left] = 1;
                dist[left, i] = 1;
                dist[i, right] = 1;
                dist[right, i] = 1;
            }

            int largest = 0;
            List<int> ll = new List<int>();

            for (int i = 0; i < k; i++)
            {
                largest = 0;
                be = Console.ReadLine().Split();

                dist[int.Parse(be[0]), int.Parse(be[1])] = 1;
                dist[int.Parse(be[1]), int.Parse(be[0])] = 1;


                for (int sta = 1; sta < n*m+1; sta++)
                {
                    for (int end = 1; end < n*m+1; end++)
                    {
                        for (int koz = 1; koz < n*m+1; koz++)
                        {
                            //if (sta == end || dist[sta,end] == 1)
                            //{
                            //    break;
                            //}

                            if (dist[sta,end] > dist[sta,koz] + dist[koz, end]) //problema -> előbb nezi meg d[4,9]-t mint 
                            {
                                dist[sta, end] = dist[sta, koz] + dist[koz, end];
                                dist[end, sta] = dist[sta, koz] + dist[koz, end];
                            }
                        }
                    }
                }

                for (int x = 1; x < n*m+1; x++)
                {
                    for (int y = x + 1; y < n*m+1; y++)
                    {
                        if (dist[x,y] > largest)
                        {
                            largest = dist[x, y];
                        }
                    }
                }

                //Console.WriteLine(largest);
                ll.Add(largest);
            }

            foreach (var item in ll)
            {
                Console.WriteLine(item);
            }

            Console.ReadLine();
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base28/50
1Accepted0/032ms20680 KiB
2Time limit exceeded0/0601ms4480 KiB
3Accepted2/232ms21772 KiB
4Accepted2/232ms21920 KiB
5Accepted2/232ms22268 KiB
6Accepted2/235ms22172 KiB
7Accepted2/2141ms22344 KiB
8Wrong answer0/2138ms22604 KiB
9Accepted2/2138ms22552 KiB
10Accepted2/257ms22684 KiB
11Accepted2/2138ms23108 KiB
12Time limit exceeded0/2564ms6360 KiB
13Time limit exceeded0/3542ms6304 KiB
14Accepted3/3171ms23460 KiB
15Time limit exceeded0/3569ms6588 KiB
16Wrong answer0/3143ms23160 KiB
17Time limit exceeded0/3549ms6684 KiB
18Accepted3/3250ms23836 KiB
19Wrong answer0/332ms23524 KiB
20Accepted3/339ms23620 KiB
21Accepted3/3337ms23960 KiB
22Time limit exceeded0/3560ms7436 KiB