编程介的小学生 2020-02-16 12:09 采纳率: 20.5%
浏览 229

Dolphin 海豚的问题

Problem Description
Dolphins are marine mammals that are closely related to whales and porpoises. They might have some kind of the biggest brains in the water, but are dolphins really smart? Some scientists say that they use their big brains to stay warm in the sea, rather than for lots of thinking. Obviously those scientists don’t think dolphins are smart.
We know that the brain is made up of two types of cells – neurons and glia. Neurons do the thinking, while glia do things like keeping the brain warm to help the neurons. After looking at how dolphins’ brains are put together, they claim that dolphins have lots of glia and not many neurons.
In order to find out how smart the dolphins are, we throw one of them into a maze we've just created, to see how long it'll take the dolphin to get out.
The maze consists of nodes and bidirectional edges connecting them.
The dolphin needs power to swim, so we place exactly one fish at each node for him to enjoy.
The dolphin is not interested in eating the same kind of fish more than once, but he can't resist any food if it's just in front to him! As a result, the dolphin decided to PLAN a route before going, so that it will not REACH any kind of fish more than once.
Given the information above, can you tell me the minimum time that the dolphin needs to get out?

Input
The first line consists of an integer T, indicating the number of test cases.
The first line of each case consists of four integers N, M, S and E, indicating the number of nodes, the number of edges, the starting node and destination.
Each of the next M lines consists of three integers U, V, C, indicating that there is an edge with length C between node U and V. It will take a dolphin C time to pass this edge.
The next line consists of N integers. Ki indicates the label of which kind fishes i-th node has.

Output
Output the minimum time that a dolphin needs to get to the destination on a single line. If a dolphin can never get to the destination, please output -1.
Constraints
0 < T <= 20
2 <= N <= 100; 0 <= M <= 10000; 0 <= S, E < N
0 <= U, V < N; 0 < C <= 1000
0 <= Ki < 1000
There may be more than one edge between two nodes, and may be loop, an edge that begins and ends both on the same vertex. All edges are bidirectional.

Sample Input
2
2 1 0 1
0 1 1
0 0
4 4 0 3
0 1 1
1 3 1
0 2 2
2 3 2
0 0 1 2

Sample Output
-1
4

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 matlab数字图像处理频率域滤波
    • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
    • ¥15 ELGamal和paillier计算效率谁快?
    • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
    • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
    • ¥15 Arcgis相交分析无法绘制一个或多个图形
    • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
    • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
    • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
    • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误