35992023-03-01 09:37:13AGergoRácsháló gráfcsharpTime limit exceeded 28/50569ms24412 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/029ms20636 KiB
2Time limit exceeded0/0560ms4468 KiB
3Accepted2/232ms21692 KiB
4Accepted2/230ms21792 KiB
5Accepted2/230ms22056 KiB
6Accepted2/232ms22064 KiB
7Accepted2/2143ms22440 KiB
8Wrong answer0/2143ms22616 KiB
9Accepted2/2143ms22480 KiB
10Accepted2/259ms22592 KiB
11Accepted2/2143ms22564 KiB
12Time limit exceeded0/2560ms5984 KiB
13Time limit exceeded0/3554ms6460 KiB
14Accepted3/3175ms23200 KiB
15Time limit exceeded0/3554ms6832 KiB
16Wrong answer0/3150ms23940 KiB
17Time limit exceeded0/3524ms7248 KiB
18Accepted3/3256ms23944 KiB
19Wrong answer0/332ms23768 KiB
20Accepted3/339ms24412 KiB
21Accepted3/3344ms24228 KiB
22Time limit exceeded0/3569ms7592 KiB