PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000008. Điểm gặp của Miguel (Meeting Prof. Miguel)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Điểm gặp của Miguel (Meeting Prof. Miguel)
Meeting Prof. Miguel
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Two travellers have distinct road networks, one for young (Y) and another for mature (M). Roads may be one-way (U) or two-way (B). Find the minimum combined cost and all optimal meeting locations in alphabetic order.
Input
lines of age direction a b w, then the two initial locations.
Output
Print You will never meet. if impossible; otherwise print minimum cost followed by all optimal meeting letters.
Subtasks
- Subtask 1 (40 points): ; ; ; .
- Subtask 2 (60 points): ; ; .
Examples
Input
2
Y B A B 2
M B C B 3
A C
Output
5 B
Explanation
The young traveller uses A-B at cost ; the mature traveller uses C-B at cost . They meet at B for total cost .