Logo
(追記) (追記ここまで)

15208번 - Brackets 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.2 초 512 MB142252030.303%

문제

A bracket symbol is one of the following: ()[]{}<>. A correct bracket expression is any string consisting of bracket symbols, such that:

  • Every left bracket has a matching right bracket of the same kind, and every right bracket is matched;
  • No two pairs of matching brackets cross -- for every two such pairs, they are either disjoint or one is contained inside the other.

For example, ([])<> is a correct bracket expression, whereas <{>} is not, as the curly brackets and angle brackets cross each other.

You are given a graph of $n$ vertices in which every (directed) edge is labeled with one of the bracket symbols. A path in this graph is valid, if its edges form a correct bracket expression. For some two vertices $s$ and $t,ドル determine the length of a shortest valid path between $s$ and $t$. We allow the path to pass multiple times through any vertex.

입력

On the first line of input there are four integers $n, m, s, t$ (1ドル \leq n \leq 200,ドル 0ドル \leq m \leq 2000,ドル 1ドル \leq s, t \leq n$) -- the number of vertices, edges, starting and ending vertex, respectively.

Each of the following $m$ lines contains two integers $x,ドル $y$ and a bracket symbol $b$ (1ドル \leq x, y \leq n$), which describe one graph edge. Note that there may be loops and multiple edges.

출력

Output a single line containing a single integer -- the length of the shortest valid path between $s$ and $t$. If there is no such path, output $-1$. You may assume that if a path exists, its length does not exceed 10ドル^{18}$.

제한

예제 입력 1

4 4 1 4
1 2 (
2 2 [
2 3 ]
3 4 )

예제 출력 1

4

예제 입력 2

5 4 1 5
1 2 <
2 3 {
3 4 >
4 5 }

예제 출력 2

-1

힌트

출처

Camp > Czech, Polish and Slovak Preparation Camp > CPSPC 2017 2-3번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /