zoukankan      html  css  js  c++  java
  • POJ 3278 The merchant

    传送门

    Time Limit: 3000MS  Memory Limit: 65536K

    Description

    There are N cities in a country, and there is one and only one simple path between each pair of cities. A merchant has chosen some paths and wants to earn as much money as possible in each path. When he move along a path, he can choose one city to buy some goods and sell them in a city after it. The goods in all cities are the same but the prices are different. Now your task is to calculate the maximum possible profit on each path.

    Input

    The first line contains N, the number of cities.
    Each of the next N lines contains wi the goods' price in each city.
    Each of the next N-1 lines contains labels of two cities, describing a road between the two cities.
    The next line contains Q, the number of paths.
    Each of the next Q lines contains labels of two cities, describing a path. The cities are numbered from 1 to N.

    1 ≤ N, wi, Q ≤ 50000

    Output

    The output contains Q lines, each contains the maximum profit of the corresponding path. If no positive profit can be earned, output 0 instead.

    Sample Input

    4
    1 
    5 
    3 
    2
    1 3
    3 2
    3 4
    9
    1 2
    1 3
    1 4
    2 3
    2 1
    2 4
    3 1
    3 2
    3 4

    Sample Output

    4
    2
    2
    0
    0
    0
    0
    2
    0
    

    Source

     
    Solution:
    题目大意:
    给一颗带点权的树,考虑从点$u$到点$v$的路径, ($v_1, v2, ..., v
  • 相关阅读:
    Python简介
    开博啦
    关于ajax访问跨域问题
    关于PHP empty()函数的错误理解
    if判断 和&&
    元素和节点
    详解js和jquery里的this关键字
    document.body的一些用法以及js中的常见问题
    浏览器报错显示
    getAttribute()获取属性
  • 原文地址:https://www.cnblogs.com/Patt/p/5476811.html
Copyright © 2011-2022 走看看