PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000067. Bưu tá lại rung chuông (The Postal Worker Rings Once)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Bưu tá lại rung chuông (The Postal Worker Rings Once)
The Postal Worker Rings Once
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Street names encode their endpoints as their first and last lowercase letters, and the street cost is its length. The undirected street network is connected and has at most two odd-degree vertices. Find the shortest closed postman walk traversing every street at least once.
Input
First m; then m lowercase street names of length between 2 and 50 with differing first and last characters.
Output
Print the total length of the minimum closed postman route.
Subtasks
- Subtask 1 (40 points): . Street names consist only of lowercase English letters. The network is connected and has at most two odd-degree vertices.
- Subtask 2 (60 points): . Street names consist only of lowercase English letters. The network is connected and has at most two odd-degree vertices.
Examples
Input
3
ab
bc
ca
Output
6
Explanation
The three length-2 streets form an Eulerian triangle; walking each exactly once and returning to the start costs 2+2+2=6.