The famous global economic crisis is approaching rapidly, so the state dịch - The famous global economic crisis is approaching rapidly, so the state Việt làm thế nào để nói

The famous global economic crisis i

The famous global economic crisis is approaching rapidly, so the states of Berman, Berance and Bertaly formed an alliance and allowed the residents of all member states to freely pass through the territory of any of them. In addition, it was decided that a road between the states should be built to guarantee so that one could any point of any country can be reached from any point of any other State.

Since roads are always expensive, the governments of the states of the newly formed alliance asked you to help them assess the costs. To do this, you have been issued a map that can be represented as a rectangle table consisting of n rows and m columns. Any cell of the map either belongs to one of three states, or is an area where it is allowed to build a road, or is an area where the construction of the road is not allowed. A cell is called passable, if it belongs to one of the states, or the road was built in this cell. From any passable cells you can move up, down, right and left, if the cell that corresponds to the movement exists and is passable.

Your task is to construct a road inside a minimum number of cells, so that it would be possible to get from any cell of any state to any cell of any other state using only passable cells.

It is guaranteed that initially it is possible to reach any cell of any state from any cell of this state, moving only along its cells. It is also guaranteed that for any state there is at least one cell that belongs to it.
Input

The first line of the input contains the dimensions of the map n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns respectively.

Each of the next n lines contain m characters, describing the rows of the map. Digits from 1 to 3 represent the accessory to the corresponding state. The character '.' corresponds to the cell where it is allowed to build a road and the character '#' means no construction is allowed in this cell.
Output

Print a single integer — the minimum number of cells you need to build a road inside in order to connect all the cells of all states. If such a goal is unachievable, print -1.
Sample test(s)
0/5000
Từ: -
Sang: -
Kết quả (Việt) 1: [Sao chép]
Sao chép!
The famous global economic crisis is approaching rapidly, so the states of Berman, Berance and Bertaly formed an alliance and allowed the residents of all member states to freely pass through the territory of any of them. In addition, it was decided that a road between the states should be built to guarantee so that one could any point of any country can be reached from any point of any other State.Since roads are always expensive, the governments of the states of the newly formed alliance asked you to help them assess the costs. To do this, you have been issued a map that can be represented as a rectangle table consisting of n rows and m columns. Any cell of the map either belongs to one of three states, or is an area where it is allowed to build a road, or is an area where the construction of the road is not allowed. A cell is called passable, if it belongs to one of the states, or the road was built in this cell. From any passable cells you can move up, down, right and left, if the cell that corresponds to the movement exists and is passable.Your task is to construct a road inside a minimum number of cells, so that it would be possible to get from any cell of any state to any cell of any other state using only passable cells.It is guaranteed that initially it is possible to reach any cell of any state from any cell of this state, moving only along its cells. It is also guaranteed that for any state there is at least one cell that belongs to it.InputThe first line of the input contains the dimensions of the map n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns respectively.Each of the next n lines contain m characters, describing the rows of the map. Digits from 1 to 3 represent the accessory to the corresponding state. The character '.' corresponds to the cell where it is allowed to build a road and the character '#' means no construction is allowed in this cell.OutputPrint a single integer — the minimum number of cells you need to build a road inside in order to connect all the cells of all states. If such a goal is unachievable, print -1.Sample test(s)
đang được dịch, vui lòng đợi..
Kết quả (Việt) 2:[Sao chép]
Sao chép!
Cuộc khủng hoảng kinh tế toàn cầu nổi tiếng là nhanh chóng tiếp cận, vì vậy các bang Berman, Berance và Bertaly hình thành một liên minh và cho phép các cư dân của tất cả các quốc gia thành viên được tự do đi qua lãnh thổ của bất kỳ của họ. Ngoài ra, nó đã được quyết định rằng một con đường giữa các quốc gia cần phải được xây dựng để đảm bảo quá một mà có bất kỳ điểm nào của bất cứ nước nào có thể đạt được từ bất kỳ điểm nào của bất kỳ nước nào khác. Từ khi con đường luôn đắt tiền, các chính phủ của các tiểu bang của liên minh mới được thành lập yêu cầu bạn để giúp họ đánh giá chi phí. Để làm điều này, bạn đã được ban hành một bản đồ có thể được biểu diễn như một bảng chữ nhật gồm n hàng và cột m. Bất kỳ tế bào của bản đồ, hoặc thuộc về một trong ba trạng thái, hoặc là một khu vực mà nó được cho phép để xây dựng một con đường, hoặc là một khu vực nơi xây dựng nền đường là không được phép. Một tế bào được gọi là khá, nếu nó thuộc về một trong những tiểu bang, hoặc đường được xây dựng trong các tế bào này. Từ bất kỳ tế bào khá bạn có thể di chuyển lên, xuống, trái và phải, nếu các tế bào tương ứng với phong trào tồn tại và là mức khá. Nhiệm vụ của bạn là xây dựng một con đường bên trong một số lượng tối thiểu của các tế bào, do đó, nó sẽ có thể để có được từ tế bào bất kỳ tiểu bang nào với bất kỳ tế bào của bất kỳ nhà nước khác bằng cách sử dụng các tế bào chỉ ở mức khá. Nó được đảm bảo rằng ban đầu nó có thể đạt được bất kỳ tế bào của bất kỳ nhà nước từ bất kỳ tế bào của tiểu bang này, di chuyển chỉ dọc theo tế bào của nó. Nó cũng được đảm bảo rằng đối với bất kỳ nhà nước có ít nhất một tế bào thuộc về nó. Input Dòng đầu tiên của đầu vào có chứa các kích thước của n bản đồ và m (1 ≤ n, m ≤ 1000) - số lượng hàng và cột tương ứng. Mỗi phòng trong số n dòng tiếp theo chứa các ký tự m, mô tả các hàng của bản đồ. Chữ số 1-3 đại diện cho các phụ kiện cho nhà nước tương ứng. Nhân vật '.' tương ứng với các tế bào, nơi nó được cho phép để xây dựng một con đường và các ký tự '#' có nghĩa là không xây dựng được cho phép trong các tế bào này. Output In một số nguyên duy nhất - số lượng tối thiểu của các tế bào bạn cần xây dựng một con đường bên trong để kết nối tất cả các tế bào của tất cả các nước. Nếu một mục tiêu như vậy là không thể thực hiện, in ra -1. Kiểm tra mẫu (s)














đang được dịch, vui lòng đợi..
 
Các ngôn ngữ khác
Hỗ trợ công cụ dịch thuật: Albania, Amharic, Anh, Armenia, Azerbaijan, Ba Lan, Ba Tư, Bantu, Basque, Belarus, Bengal, Bosnia, Bulgaria, Bồ Đào Nha, Catalan, Cebuano, Chichewa, Corsi, Creole (Haiti), Croatia, Do Thái, Estonia, Filipino, Frisia, Gael Scotland, Galicia, George, Gujarat, Hausa, Hawaii, Hindi, Hmong, Hungary, Hy Lạp, Hà Lan, Hà Lan (Nam Phi), Hàn, Iceland, Igbo, Ireland, Java, Kannada, Kazakh, Khmer, Kinyarwanda, Klingon, Kurd, Kyrgyz, Latinh, Latvia, Litva, Luxembourg, Lào, Macedonia, Malagasy, Malayalam, Malta, Maori, Marathi, Myanmar, Mã Lai, Mông Cổ, Na Uy, Nepal, Nga, Nhật, Odia (Oriya), Pashto, Pháp, Phát hiện ngôn ngữ, Phần Lan, Punjab, Quốc tế ngữ, Rumani, Samoa, Serbia, Sesotho, Shona, Sindhi, Sinhala, Slovak, Slovenia, Somali, Sunda, Swahili, Séc, Tajik, Tamil, Tatar, Telugu, Thái, Thổ Nhĩ Kỳ, Thụy Điển, Tiếng Indonesia, Tiếng Ý, Trung, Trung (Phồn thể), Turkmen, Tây Ban Nha, Ukraina, Urdu, Uyghur, Uzbek, Việt, Xứ Wales, Yiddish, Yoruba, Zulu, Đan Mạch, Đức, Ả Rập, dịch ngôn ngữ.

Copyright ©2024 I Love Translation. All reserved.

E-mail: