I. Knight's Tour: The Beginnings

Codeforces
IDCF10253I
Time2000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Properly sneaking into a mission is very important for spies, which is lucky for you, because the Cavalry Valet Movile Insertion Group (CVMIG) has given one of their horses to you. The problem is, you are not a knight yet! In order for the horse to follow your commands, it must deem you worthy of being a knight! Fortunately, proving yourself worthy of knightliness is easy. All horses are part of the chess club, and love how knights move. You just need to show them that you can get to your destination just like how a knight would. In chess, a #cf_span(class=[tex-font-style-underline], body=[knight]) moves in an L shaped pattern, moving 1 space to its side then 2 spaces forward, landing on that final square. It can hop over obstacles. Consider the following diagram: The knight, shown at the center, may move around in $8$ ways relative to the knight's current position, labeled 'A', 'B', ..., 'H'. The knight may do that even if the squares immediately surrounding it are obstacles. You will be given an $R times C$ grid of characters. Each character is one of the following: Output "Whinny" if it's possible and "Neigh" if it is not. If it is possible, also output a string denoting the moves the knight can follow to the final spot. Note that the knight cannot leave the grid. In other words, it is not allowed to perform a move if the desination cell is outside the grid. The first line of the input contains a single integer $t$, the number of test cases. $t$ test cases follow. The first line of each test case contains two integers $r$ and $c$. $r$ lines follow, each containing $c$ characters, describing the grid using the abovementioned denotations. *Constraints* $1 <= t <= 10$ $1 <= r, c <= 1000$ For each test case, output a single line containing "_Whinny_" if it's possible to reach F from K using knight moves, "_Neigh_" otherwise. If it's possible, output an additional line containing a string denoting the series of moves the knight can follow. The string should be composed of characters 'A', 'B', ..., 'H' indicating the type of move done. If there are multiple such move-strings available, output the shortest one. If there are multiple shortest move-strings, output the lexicographically-least move-string. ## Input The first line of the input contains a single integer $t$, the number of test cases. $t$ test cases follow.The first line of each test case contains two integers $r$ and $c$. $r$ lines follow, each containing $c$ characters, describing the grid using the abovementioned denotations.*Constraints*$1 <= t <= 10$$1 <= r, c <= 1000$ ## Output For each test case, output a single line containing "_Whinny_" if it's possible to reach F from K using knight moves, "_Neigh_" otherwise.If it's possible, output an additional line containing a string denoting the series of moves the knight can follow. The string should be composed of characters 'A', 'B', ..., 'H' indicating the type of move done. If there are multiple such move-strings available, output the shortest one. If there are multiple shortest move-strings, output the lexicographically-least move-string. [samples]
**Definitions** Let $ n \in \mathbb{Z}^+ $ be the number of employees. Let $ T = (V, E) $ be a rooted tree with $ V = \{1, 2, \dots, n\} $, where edge $ (j, p_j) \in E $ denotes that employee $ p_j $ is the direct superior of employee $ j $, and $ p_1 = 0 $ (root). Let $ A \in \{0,1\}^n $ be the affiliation vector: $ A_j = 1 $ if employee $ j $ is a capitalist spy, $ A_j = 0 $ if a socialist comrade. **Constraints** 1. $ 1 \le n \le 10^5 $, $ 1 \le q \le 10^5 $ 2. For each $ j \in \{2, \dots, n\} $, $ 1 \le p_j \le n $; $ p_1 = 0 $ 3. $ A_j \in \{0,1\} $ for all $ j \in \{1, \dots, n\} $ 4. For each inquiry $ (i, c, s) $: $ 1 \le i \le n $, $ 0 \le c, s \le n $ **Objective** For each inquiry $ (i, c, s) $, determine whether there exists a connected subtree $ S \subseteq V $ rooted at $ i $ such that: $$ \sum_{v \in S} A_v = c \quad \text{and} \quad \sum_{v \in S} (1 - A_v) = s $$ Output "compromised" if such $ S $ exists; otherwise, output "not compromised".
API Response (JSON)
{
  "problem": {
    "name": "I. Knight's Tour: The Beginnings",
    "description": {
      "content": "Properly sneaking into a mission is very important for spies, which is lucky for you, because the Cavalry Valet Movile Insertion Group (CVMIG) has given one of their horses to you. The problem is, you",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10253I"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Properly sneaking into a mission is very important for spies, which is lucky for you, because the Cavalry Valet Movile Insertion Group (CVMIG) has given one of their horses to you. The problem is, you...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of employees.  \nLet $ T = (V, E) $ be a rooted tree with $ V = \\{1, 2, \\dots, n\\} $, where edge $ (j, p_j) \\in E $ denotes that employee $ p_...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments