아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Robots

시간 제한10초메모리 제한256 MB

요약
로봇이 비결정적으로 이동하는 방향 그래프에서, 모든 로봇이 처음 b개의 요새 구역에 반드시 도달하게 되는 이동 횟수 k를 구하거나 -1을 출력한다.
난이도

보통10점 중 7점

유형
그래프, 정수론, 수학, 시뮬레이션
정답자
아직 제출이 없습니다

문제

Captain Byteasar supervises the colonization of a natural asteroid BA-1T which is rich in raw materials. His job is controlling the robot-miners extracting ardanium. The space weather forecast predicts a meteor shower, and it would be better if all the robots were hidden in armoured strongholds once the shower happens.

Unfortunately, the miners control system leaves much to be desired. The only thing one can do is to input a single non-negative integer kk into it, which will result in sending kk "Move up!" commands to every robot.

There are nn sectors marked out on the surface of the planet. Some of the sectors are the strongholds, and the other ones are the open pit ardanium mines. Robot-miners are equipped with quantum brains and therefore they work nondeterministically. For each sector ss, Byteasar knows a non-empty set A_sA\_s, such that any robot located in the sector ss will move to one of the sectors of A_sA\_s after receiving a command. It is generally not known which sector of A_sA\_s will be picked; one can neither count on any repeatability -- even if a certain robot has been in the sector ss a few times already, next time it can move to a sector completely different than before.

Now Byteasar wonders whether there exists such kk, that after issuing kk "Move up!" commands, each robot will be in one of the strongholds for sure.

입력

The first line of the input contains three integers nn, bb and rr (2≤n≤2002 \le n \le 200, 1≤b,r≤n{1 \le b, r \le n}), denoting the number of sectors, the number of strongholds and the number of robot-miners, respectively. The sectors are numbered 11 through nn and the sectors numbered 11 through bb are the strongholds.

This is then followed by nn lines containing descriptions of possible transitions after receiving the "Move up!" command. The ii-th of these lines contains a string of nn digits from the set {0, 1}; the jj-th of these numbers is equal to 1 if and only if a miner can move from sector ii to sector jj after receiving a command. At least one digit in a line is equal to 1.

The last line of the input contains an increasing sequence of rr numbers ranging from 11 to nn, indicating the sectors where the robot-miners are initially present.

출력

In case a number kk, sought by Byteasar, does not exist, you should output the number −1-1. Otherwise we guarantee that there exists a non-negative integer satisfying Byteasar's requirements and having at most 200 digits (in decimal notation). Then, you should output any such number.

예제2

  1. 예제 1

    입력
    4 2 2
    0100
    0010
    1001
    1000
    3 4
    
    예상 출력
    2
    
  2. 예제 2

    입력
    4 2 2
    0100
    0010
    1001
    1000
    2 3
    
    예상 출력
    -1