Codeforces 436 C. Dungeons and Candies

Source: Internet
Author: User


MST ....

C. Dungeons and Candiestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

During the loading of the game "Dungeons and Candies" you are required to get descriptionsKLevels from the server. Each description is a map ofN? ×?MCheckered rectangular field. some cells of the field contain candies (each cell has at most one candy ). an empty cell is denoted ". "on the map, but if a cell has a candy, it is denoted as a letter of the English alphabet. A level may contain in identical candies, in this case the letters in the corresponding cells of the map will be the same.

When you transmit infZ records? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> latency + QTwvZW0 + latency + q1_vzw0 + latency + ZDwvZW0 + latency/latency + QTwvZW0 + latency + q1_vzw0 + latency + QTwvZW0 + LD88ZW0 + pushed/pushed + h3D88ZW0 + bjwvZW0 + LD88ZW0 + pushed/odw/pushed + bjwvZW0 + pushed = ". "). please note that the case of the letters matters.

Output

In the first line print the required minimum number of transferred bytes.

Then printKPairs of integersX1 ,?Y1 ,?X2 ,?Y2 ,?...,?XK,?YK, Describing the way to transfer levels. PairXI,YIMeans that levelXINeeds to be transferred by wayYI. IfYIEquals 0, that means that the level must be transferred using the first way, otherwiseYIMust be equal to the number of a previusly transferred level. It means that you will transfer the difference between levelsYIAndXITo transfer levelXI. Print the pairs in the order of transferring levels. The levels are numbered 1 throughKIn the order they follow in the input.

If there are multiple optimal solutions, you can print any of them.

Sample test (s) input
2 3 3 2A.A...A.a..CX.Y...
Output
141 02 13 1
Input
1 1 4 1A.B.
Output
31 02 04 23 0
Input
1 3 5 2ABABBBBBABABABB
Output
111 03 12 34 25 1

#include 
 
  #include 
  
   #include 
   
    #include #include 
    
     using namespace std;struct Edge{    int u,v,w;}edge[1100*1100];bool cmp(Edge a,Edge b){    return a.w
     
       vc[1100];int get_diff(char a[][20],char b[][20] ){    int ret=0;    for(int i=0;i
      
       


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.